database - custom mysql function - cant pass parameters down -


as title states. here's function

delimiter // create function getcreatevalue( table_name char(64), id_field char(64), name_field char(64), name_value char(64) ) returns integer begin     declare ret integer;     select count(*) ret table_name name_field = name_value;     if ret < 1         insert table_name set name_field = name_value;         select id_field ret table_name name_field = name_value;     else             select id_field ret table_name name_field = name_value;     end if;     return ret; end// delimiter ; 

when run like

select getcreatevalue('table1', 'id', 'name', '123456'); 

i error table "table_name" does't exist. parameter wasnt passed. why?

set @qry =     concat(      'select count(*) ret ', table_name,        ' ', name_field,        ' = ?');  prepare stmt1 @qry; set @v = name_value; execute stmt1 using @v; deallocate prepare stmt1; 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -