Subject Re: [Firebird-Architect] Re: Cursors
Author Daniel Rail
Hello Roman,

Saturday, June 5, 2004, 3:19:26 PM, you wrote:

>> Well, it makes sense if he includes an order by clause. But there
>> is no way to determine the desired records in that case other than
>> determining at least the first 50,010 records. So, the
>> "first...skip" solution is as good as possible.

> I think it's not about the displaying records 50,000 to 50,010, but
> rather about scrollable cursors and operations related to them
> (first(), last(), absolute(n), etc.).

> So we are back to the discussion "Scrollable cursors: to be or not to
> be". Can anobody tell do Oracle, DB2 and MS SQL implement them and how?

They all support scrollable cursors on the "result set", by using the
DECLARE CURSOR statement. It is just a more fully implemented version
of the DECLARE CURSOR(and related commands) in FB. It is part of the
SQL standards, and surprisingly MS-SQL is pretty close to the standard.

Here's an example of how it would work, do notice FETCH ABSOLUTE,
which is not currently implemented in FB:

DECLARE myCursor SCROLL WITH RETURN CURSOR
FOR SELECT * FROM myTable
FOR UPDATE;
OPEN myCursor;
FETCH ABSOLUTE 50000 FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
FETCH NEXT FROM myCursor INTO :returnvar1, :returnvar2;
CLOSE myCursor;


I can provide the SQL standard syntax if someone wants it. And, as it
stands in the standard and the other major RDBMS servers, scrollable
cursors are temporary and used with a result set.

--
Best regards,
Daniel Rail
Senior Software Developer
ACCRA Group Inc. (www.accra.ca)
ACCRA Med Software Inc. (www.filopto.com)