FORUM Tom's Hardware » Programmation » PHP & MySQL & ASP » trouble with MYSQL 5 FUNCTION
 

trouble with MYSQL 5 FUNCTION

Il y a 519 utilisateurs connus et inconnus. Pour voir la liste des connectés connus, cliquez ici
Ajouter une réponse



 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : trouble with MYSQL 5 FUNCTION
 
Plus d'informations

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

zeb
Plus d'informations

Dear sql_noob,
 
Here is THFR, the French version [:l_ecorcheur] of  Tom's Hardware forum.
Please subscribe to http://www.tomshardware.com/us (http://img.tomshardware.com/flags/usa.gif) or http://www.tomshardware.co.uk (http://img.tomshardware.com/flags/uk.gif / http://img.tomshardware.com/flags/ireland.gif) if you can only speak english.
 
Yours,
Zeb


---------------
Règlement du forum / Règlement de Programmation / Règlement du Monde de Linux euh, n'y en a pas...

Aller à :
Ajouter une réponse
  FORUM Tom's Hardware » Programmation » PHP & MySQL & ASP » trouble with MYSQL 5 FUNCTION
 

Annonces Google
Publicité