Unanswered: how to indicate which statement is executing in a procudure/function
USually, there are serveral statements in a user-defined SQL procedure/function. Learning which statement in a procedure/function is executing is helpful for debugging. In C/C++, we can insert printf(...) between statements.
This can be improved by adding a time at the front so you can see if anything is taking too long to execute. The disadvantage of having just plain select statements is that you'll need to comment them out when the code goes live and, if you suddenly find you need this info again, you'll need to uncomment everything to see the logging. The other disadvantage is that your users will see the logging also.
Logging can be improved by adding a where clause with a global flag so you can turn debugging on or off at any time. Another improvement is to insert the log info into a log table rather than to the screen so you can read it at any time.
You could also finish things off nicely by writing a stored procedure to do the logging for you and then have different levels of logging (info, log, warning or error) so only certain messages are stored depending on your global flag.
call db_log_action( in_user_id, 'log', "Re-aligned ids in database" );
If you're calling the procedure via isql etc then it will work fine. However if you're calling it from a program, like PHP, then the program will wonder what it has to do with the string it's suddenly been passed and hence gives you this error.
My suggestion is to either test the proc by hand in isql. Better still, insert the test data into a log table. You will need to select the data out of the log table to read it.
# create a log table
create table MyLogTable (
# in your procedure have statements like this
insert MyLogTable values ( now(), "starting proc xxx" );
# later when you want to see what's happened
select * from MyLogTable order by log_time;