#7 Mysql fetch_scroll(SQL_FETCH_PRIOR)

open
nobody
None
5
2002-12-04
2002-12-04
Bill Black
No

I discovered that the
Mysql::Statement::fetch_scroll(SQL_FETCH_PRIOR) does
not fetch the prior row, but the current row. It seems
to be easily fixed by decrementing @current_row like this:

...
def fetch_scroll(direction, offset)
case direction
when SQL_FETCH_NEXT
@current_row += 1
fill_array(@res_handle.fetch_row)
when SQL_FETCH_PRIOR
+ @current_row -= 1
@res_handle.data_seek(@current_row - 1)
fill_array(@res_handle.fetch_row)
when SQL_FETCH_FIRST
...

Of course there may be some gotcha that I dont know
about, since i am three days new to ruby.
Ruby seems like a real nice language, I think I am
going to like it.
Thanks to all you guys for making the DBI work.

Bill

Discussion