Here’s a little topo on having, from time to time, null values in the Fetch of a MySQL cursor. While cursor query returns data well.
This is a problem I’ve encountered twice already. And before asking myself the right questions, I spend a lot of time debugging my code without really understanding. So I’m also sharing it with you in case you encounter the problem.
The problem can happen when using MySQL cursors (the detail of their use is described in this article ).
I just ran into the case (with MySQL 5.5) when the problem is old but hasn’t been fixed (and isn’t considered a bug by the way, so it probably never will be).
The case:
I have a MySQL procedure that uses a cursor to loop over a record. At each turn, a fetch is used to feed variables, which are then used to perform certain calculations. A relatively classic case.
However, at each exit, the calculation that should have given me a number answered NULL. Digging a little deeper, I checked the status of my Fetch powered variables. And most of my variables were NULL, while the base line includes data.
By dint of searching, I ended up searching the web, and I came across this page on the MySQL site .
The cause of the problem was related to the fact that the variables I used had the same name as the database fields. This can be discussed, moreover, if it is a bad practice or not, but it can still create problems.
Good to know then.