Unix Technical Forum

Variables not been updated when I fetch a cursor

This is a discussion on Variables not been updated when I fetch a cursor within the MySQL General forum forums, part of the MySQL category; --> Hello there, I have a problem, I wrote a stored procedure to retrieve some data from various tables and ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:47 AM
Sergio Bobillier
 
Posts: n/a
Default Variables not been updated when I fetch a cursor

Hello there,

I have a problem, I wrote a stored procedure to retrieve some data
from various tables and then put it in a temporary table to use it
later, most of the procedure works just fine but there's something
that doesn't and I can not guess what the error can be.

Okay so, here's the thing:

I declared a cursor that joins some tables:

DECLARE cur_libros CURSOR FOR SELECT ISBN, CONCAT(Nombre, " ",
Apellido), Nombre_Editorial, YEAR(Fecha_publicacion), Precio, Titulo
FROM Autor JOIN Libro_Autor USING(Id_autor) JOIN Libro USING(ISBN)
JOIN Libro_Editorial USING(ISBN) JOIN Editorial USING(Id_Editorial)
WHERE Nombre = nom AND Apellido = ap;

[ When I execute the SELECT sentence for this cursor it works just
fine, the records are retrieved as I want them, so I know it isn't a
problem with the table or the JOIN. ]

Later in the procedure I fetch the cursor data into some local
variables I have declared:

FETCH cur_libros INTO myisbn, nombre_autor, editorial,
ano_publicacion, precio, titulo;

most of the variables are filled with data after the fetch but precio
and titulo are not. I searched the Internet trying to find a solution
and ended up in a bug report for mySQL:

Bug #8692
Cursor fetches null values into variables

Suggested fix:
Variables should contain valid data. Fetch should fetch valid data
into the variables.

So I added some SET sentences to initialize the variables before
fetching data into them:

SET titulo = "";
SET precio = 0;

Still nothing... in fact the variables are never updated is not that
the fetch set them to null is more like the fetch just don't touch
them, they are never modified, no matter what I initialize them to the
variables never change.

I tried to check the data types to make sure they are the same that
the ones in the table and the data types are Ok they match, so... What
is the problem here?

What are the more common causes for a variable not been updated in a
FETCH? If I would have a little idea about that I could figure out
what the problem is, so I would really appreciate your help.

Thanks in advance.

--
Sergio
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:12 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com