Generating a table and filling the table with data
session.sql ('CREATE TABLE cursortest (A INT KEY)')
insert = session.prepare ('INSERT INTO cursortest (A) VALUES (?)')
for i in xrange (1, 11):
insert.execute ([i])
Generating a results set
cursor = session.sql ('SELECT A FROM cursortest ORDER BY A')
The cursor is positioned before the first record.
You position the cursor on the next record (the first record, initially), and display this record:
>>> cursor.next ()
(1,)
You position the cursor on the next record and display this record:
>>>cursor.next ()
(2,)
You position the cursor on the previous record and display this record:
>>> cursor.previous ()
(1,)
You move the cursor five records ahead and display this record:
>>> cursor.relative (5)
(6,)
You move the cursor one record back and display this record:
>>>cursor.relative (-1)
(5,)
You position the cursor on the third record of the results set and display this record:
>>> cursor.absolute (3)
(3,)
You position the cursor on the third last record of the results set and display this record:
>>>cursor.absolute (-3)
(8,)
You position the cursor on the first record of the results set and display this record:
>>> cursor.first ()
(1,)
You position the cursor on the last record of the results set and display this record:
>>> cursor.last ()
(10,)
You display the record on which the cursor is currently positioned:
>>> cursor.current ()
(10,)
You iterate across the entire results set:
>>> for row in cursor: print row,
(1,) (2,) (3,) (4,) (5,) (6,) (7,) (8,) (9,) (10,)