I am writing a stored procedure in which I am using dynamic variables to define a block of SQL. I then create a prepared statement from the dynamic variable and execute it.
When my SQL gets longer than 255 chars it gets truncated (presumably a limit dynamic variables).
set @NEW_CAMPAIGN_SQL = concat(
'CREATE TABLE `', CAMPAIGN_TABLE, '` (',
'`id` bigint(20) unsigned NOT NULL auto_increment,',
'`code` char(', _CODE_LEN, ') NOT NULL default \'\',',
'`status` tinyint(1) unsigned NOT NULL default 1,',
'PRIMARY KEY (`id`),',
'KEY `code_idx` (`code`),',
'KEY `status_idx` (`status`)',
') ENGINE=InnoDB DEFAULT CHARSET=latin1'
);
PREPARE NEW_CAMPAIGN_STMT FROM @NEW_CAMPAIGN_SQL;
EXECUTE NEW_CAMPAIGN_STMT;
Deallocate prepare NEW_CAMPAIGN_STMT;
I tried just declaring NEW_CAMPAIGN_SQL as a non-dynamic variable but then the prepared statement fails.
Any suggestions would be appreciated.
Ah crap. As is typically the case it was my own stupidity and not the fault of MySQL in any way. I was returning the SQL string to an OUT param that was varchar(255).
Thanks for the help!