Hi all i have a trouble to use a mysql 5 function i made. First i will show you the way it's work and the next one try to use 2 other parameter and don't work
--
-- This function work perfecly but i need to hardcode the field name (english) + the table name (table_msg) of my database
--
DROP FUNCTION IF EXISTS hyb_create_ref_msg//
CREATE FUNCTION hyb_create_ref_msg(msg_id text) returns text DETERMINISTIC
BEGIN
DECLARE tmp_msg text;
SET table_msg = CONCAT(prefix ,'_msg');
IF msg_id > 0 THEN
SELECT `english` INTO tmp_msg FROM `boom_msg` WHERE `id` = msg_id;
ELSE
SET tmp_msg = Null;
END IF;
return tmp_msg;
END;//
Note that this line:
SELECT `english` INTO tmp_msg FROM `boom_msg` WHERE `id` = msg_id;
work perfecly and use the (`id` = msg_id )
So i change my function to use 2 other parameter lng,prefix for remove the hardcode field + table name
it's look like this
--
-- function that take the lng and the prefix parameter
--
DELIMITER //
DROP FUNCTION IF EXISTS hyb_create_ref_msg//
CREATE FUNCTION hyb_create_ref_msg(msg_id text, lng text, prefix text) returns text DETERMINISTIC
BEGIN
DECLARE tmp_msg text;
DECLARE table_msg text;
SET table_msg = CONCAT(prefix , '_msg' );
IF msg_id > 0 THEN
SELECT lng INTO tmp_msg FROM table_msg WHERE `id` = msg_id;
ELSE
SET tmp_msg = Null;
END IF;
return tmp_msg;
END;//
if i call hyb_create_ref_msg('10','english','boom_msg') in a select
the result is that this function try to realy select the field 'lng' and in the table 'table_msg'
when its supposed to select field 'english' in the table 'boom_msg'
If someone can help me it will be realy appreciate
Many Thanks