How To Use Cursors With a SQL Query Object
After setting properties for a SQL Query object you can use sqlquery_retrieveAsArray, sqlquery_retrieveAsData and sqlquery_retrieveAsRecords to retrieve your data without having to fuss with a database cursor. But what do you do if you need to access the database cursor for a query? This lesson will show you.
sqlquery_retrieve
A SQL Query object can open a database cursor using sqlquery_retrieve. This command generates a SQL query using the SQL Query object properties and then opens the database cursor. You are then responsible for closing the database cursor using sqlquery_close.
You can access the RevDB cursor id through the "cursor" property:
put sqlquery_get(theQueryA, "cursor") into theCursor
put the result into theError
## Do something with the cursor
sqlquery_close theQueryA
Navigating the Cursor
Once you have opened a database cursor there are a couple of SQL Query object handlers that help navigate the cursor. They are:
• sqlquery_moveToFirstRecord
• sqlquery_moveToLastRecord
• sqlquery_moveToNextRecord
• sqlquery_moveToPreviousRecord
• sqlquery_moveToRecord
Here is an example:
put sqlquery_createObject("lessons") into theQueryA
sqlquery_set theQueryA, "conditions", "id < 4"
sqlquery_retrieve theQueryA
put the result into theError
if theError is empty then
sqlquery_moveToNextRecord theQueryA
if the result is true then
## You are now on the second record in the result set.
end if
end if
0 Comments
Add your comment