开发者

MySQL Cursor Open Fails

So, I am trying to setup a mysql stored procedure to work with a cursor, and for whatever reason, the cursor fails to open and (as far as I can tell) causes the SP to stop. Here is the cursor declaration

  DECLARE cur_networks CURSOR FOR 
SELECT td.name FROM drupal5.users u 
LEFT JOIN drupal5.term_user tu 
ON u.uid = tu.uid 
LEFT JOIN drupal5.term_data td 
ON td.tid = tu.tid 
WHERE u.uid = tmpint;

tmpint is a variable declared earlier in the SP:

DECLARE tmpint int;

and it's value is set here:

  SELECT t1.uid, t1.mail FROM drupal5.users t1 WHERE t1.name = Drupal_User_Name
      INTO tmpint, Drupal_Email;

Then I do a bunch of other things in the script, all of which appear to be working fine, but when I get to this line:

OPEN cur_networks;

Things come crashing down. I've got some logging enabled ala this article: http://www.bluegecko.net/mysql/debugging-stored-procedures/

Which is working great. If I terminate the output before the OPEN command, I can see everything looks to be working normal. If I terminate the output after the OPEN command, nothing is saved to the log, which indicates that line is the problem. I have no idea why. It's probably something ridiculous simple, but I开发者_如何学运维 can't seem to spot it. Thanks in advance. I will post more of the SP if that is necessary to spot the problem.


The problem was a permission issue. The MySQL user executing the query did not have read access to the term_user or term_data tables.

The moral of the story is that if an application is executing your SP and it's not working, be sure to try running the SP directly from the MySQL console. It's the only real way to get feedback from your process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜