I am regularly trying to generate tens of thousands of new rows in a table each containing a unique serial number generated from within a stored procedure.
Using repeated INSERTS in a loop as I do at the moment is slow, so I am trying to use a multi-row INSERT, where I first create an SQL string containing the query with 1000 rows of data at a time, so then I need to use the PREPARE and EXECUTE statements to actually execute the insert statement from within the stored procedure.
I have no trouble with the multi-row insert from a command line.
MySQL is at revision 5.0.32.
Prepared statements in stored procedures have been supported since revision 5.0.13.
I am using dbForge Studio for MySQL version 3.50.305 - the very latest at present.
I have boiled my problem down to a few lines of "play" code as follows:
Code: Select all
CREATE DEFINER = 'root'@'%'
PROCEDURE pippa.PlayExecute()
BEGIN
DECLARE tui TEXT;
SET @tui = 'INSERT INTO Play (PlayNum) VALUES (30), (40);';
PREPARE xh1 FROM @tui;
EXECUTE xh1;
END
- The MySQL statement "PREPARE statement_name FROM user_variable" requires a user variable containing the SQL statement to be executed.
From an SQL command line, user variables are all undeclared and prefixed with an @ character. Within stored procedures, they are DECLARED, and should NOT be preceeded by an @
dbForge Studio reports a syntax error if I do not prefix my variable with an @, in the line PREPARE xh1 FROM @tui
I cannot DECLARE @tui - that is a syntax error
If I leave out the DECLARE line, then the variables @tui below are undeclared according to dbForge, also wrong.
When executing in the debugger, @tui and tui are two separate variables, and @tui is ALWAYS out of scope
I have tried the SET line as SET tui=... rather than SET @tui=... , but the @tui value is then NULL
When I execute the code as shown (because that is the only format in which it will "pass" syntax checking and save) with or without debug the variables tui and @tui sometimes have the same value to MySQL, mostly not.
And, yes, I know I should be using the same variable name everywhere, but dbForge won't let me.

Help please?
I am impressed by the speed of turnaround on the latest release, and thank you for including a release log on the site, but while we wait for the next release, can you please suggest a work-around?
Many thanks.
Jem
