shadd Posted September 24 Share Posted September 24 i have this procedure: DELIMITER $$ CREATE PROCEDURE sp_add_user(IN inname text,IN insex tinytext) MODIFIES SQL DATA BEGIN set @newEanswer_sql=CONCAT('INSERT INTO user(fname,sex)values("',inname,'","',insex,'")' ); PREPARE snewEans_insert FROM @newEanswer_sql; EXECUTE snewEans_insert; DEALLOCATE PREPARE snewEans_insert; END$$ DELIMITER ; when i run it like so: call sp_add_user('pierre',''); it gives me the following error: RETURNED_SQLSTATE MESSAGE_TEXT 01000 Data truncated for column 'sex' at row 1 here is table: create table user ( userid int unsigned not null auto_increment, fname text , sex enum('male','female'), Primary key(userd) ); how can i solve this?? Quote Link to comment https://forums.phpfreaks.com/topic/324227-how-to-use-enum-parameters-in-mysql-stored-procedure/ Share on other sites More sharing options...
requinix Posted September 24 Share Posted September 24 That procedure is wacky. Why is it trying to make a simple INSERT be so complicated? And so prone to not working? The error is telling you, in a weird way that doesn't seem very obvious, that the value you used is not valid. Which it clearly isn't. Quote Link to comment https://forums.phpfreaks.com/topic/324227-how-to-use-enum-parameters-in-mysql-stored-procedure/#findComment-1636002 Share on other sites More sharing options...
shadd Posted September 24 Author Share Posted September 24 8 minutes ago, requinix said: That procedure is wacky. Why is it trying to make a simple INSERT be so complicated? And so prone to not working? The error is telling you, in a weird way that doesn't seem very obvious, that the value you used is not valid. Which it clearly isn't. what if i need to account for null entries to this field Quote Link to comment https://forums.phpfreaks.com/topic/324227-how-to-use-enum-parameters-in-mysql-stored-procedure/#findComment-1636004 Share on other sites More sharing options...
requinix Posted September 24 Share Posted September 24 Don't overthink the procedure so much and just have it do the absolute most obvious thing: an INSERT statement. Quote Link to comment https://forums.phpfreaks.com/topic/324227-how-to-use-enum-parameters-in-mysql-stored-procedure/#findComment-1636007 Share on other sites More sharing options...
Solution shadd Posted September 24 Author Solution Share Posted September 24 13 minutes ago, requinix said: Don't overthink the procedure so much and just have it do the absolute most obvious thing: an INSERT statement. SOLVED IT BY ADDING IF INSEX<>''THEN DO INSERT WITH THE ENUM FIELD ELSE DO INSERT WITHOUT THE ENUM FIELD IN QUERY END IF; Quote Link to comment https://forums.phpfreaks.com/topic/324227-how-to-use-enum-parameters-in-mysql-stored-procedure/#findComment-1636008 Share on other sites More sharing options...
Barand Posted September 24 Share Posted September 24 INSERT INTO user (fname,sex) values (inname, NULLIF(insex, '') ); Quote Link to comment https://forums.phpfreaks.com/topic/324227-how-to-use-enum-parameters-in-mysql-stored-procedure/#findComment-1636010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.