FETCH RELATIVE has an off by one error for the first row
--------------------------------------------------------

                 Key: CORE-6486
                 URL: http://tracker.firebirdsql.org/browse/CORE-6486
             Project: Firebird Core
          Issue Type: Bug
          Components: Engine
    Affects Versions: 3.0.7, 4.0 RC 1
         Environment: Windows 10 64-bit
Firebird-4.0.0.2353-0-RC1-x64 / Firebird-3.0.7.33374-1_x64
            Reporter: Mark Rotteveel


The FETCH RELATIVE 1 FROM cursor_name statement should be equivalent to FETCH 
NEXT FROM cursor_name (or FETCH cursor_name), however it skips the first row;

execute block
  returns (rowval integer, rowcount integer)
as
  declare c scroll cursor for (select 1 as rowval from rdb$database union all 
select 2 as rowval from rdb$database  union all select 3 as rowval from 
rdb$database);
begin
   open c;
    -- fetch next from c;
    fetch relative 1 from c;
    rowval = c.rowval;
    rowcount = row_count;
    suspend;
end

This returns (2, 1) for (rowval, rowcount), instead of expected (1, 1). For 
subsequent fetches, it behaves as expected, so it seems to problem is with the 
first FETCH RELATIVE only. Using FETCH RELATIVE 2 FROM c will return (3,1) 
instead of (2,1).

It seems to behave as if the first row was already fetched, but using FETCH 
RELATIVE 0 FROM c will produce error "Cursor C is not positioned in a valid 
record".

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://tracker.firebirdsql.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to