If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > how to indicate which statement is executing in a procudure/function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-22-08, 05:38
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
how to indicate which statement is executing in a procudure/function

Hello ALL,

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.

Can I do this in a procedure/function

Thanks
Reply With Quote
  #2 (permalink)  
Old 11-22-08, 07:17
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
You can just use a select statement ie
Code:
select "starting proc xxx"
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.
Code:
call db_log_action( in_user_id, 'log', "Re-aligned ids in database" );
Reply With Quote
  #3 (permalink)  
Old 11-22-08, 07:41
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
thanks mike_bike_kite

Code:
Logging can be improved by adding a where clause with a global flag so you can turn debugging on or off at any time.
THis is exactly what I want. Could you please show me how and where to add a 'where clause'.

Thanks again.

Last edited by cy163; 11-22-08 at 07:50.
Reply With Quote
  #4 (permalink)  
Old 12-10-08, 06:26
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
I tested the command
Code:
select "starting proc xxx"
the command caused error "....procedure/function cannot return recordset...."
Reply With Quote
  #5 (permalink)  
Old 12-10-08, 07:01
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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.

Code:
# create a log table
create table MyLogTable (
   log_time        datetime,
   log_txt           varchar(200)
);

# 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;
Reply With Quote
  #6 (permalink)  
Old 12-10-08, 08:23
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
mike_bike_kite thanks.

Also, I found the info on the following link is helpful


http://gilfster.*************/2006/03...-in-mysql.html
Reply With Quote
  #7 (permalink)  
Old 12-10-08, 09:25
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
mike_bike_kite thanks.

Also, I found the info on the following link is helpful


http://gilfster.*************/2006/03...-in-mysql.html
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On