Bug #50202 | MySQL Cursor Returns Incorrect number of rows | ||
---|---|---|---|
Submitted: | 9 Jan 2010 4:42 | Modified: | 9 Jan 2010 5:35 |
Reporter: | Petrus Darmawan HS | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S3 (Non-critical) |
Version: | 5.1.30 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | compound statement, cursor |
[9 Jan 2010 4:42]
Petrus Darmawan HS
[9 Jan 2010 4:50]
Todd Farmer
After the sixth row in your example, the following happens: WHILE c_done = 0 DO # True, haven't yet tried to get the (non-existant) 7th row FETCH mycursor INTO myvar; # no 7th row, invoke HANDLER set c_done = 1, continue SET ctr = ctr + 1; # increment ctr to 7 END WHILE; # loop back WHILE c_done = 0 DO # False, c_done is now 1, skip DO CLOSE mycursor; RETURN ctr; # returns 7 I don't see a bug here. If you have other examples, please let us know.
[9 Jan 2010 5:35]
Petrus Darmawan HS
Thanks 4 ur explaination.. well, I modified the function WHILE c_done = 0 DO FETCH mycursor INTO myvar; SET ctr = ctr + 1; SELECT COUNT(*) INTO myvar FROM mytab; #try to add query execution END WHILE; the function still works well. But the function doesn't work like that on my other function. The cursor always stopped after it fetched 1st row. My other function is similar, but involve more tables and use WHERE conditions.