SQL_OPEN_CURSOR_STMT¶
Applies to: ORAFlex SQLFlex MYSQLFlex PGFlex DB2Flex
This command is used to create a new SQl Cursor. Once created, SQL_SET_CURRENT_CURSOR_STMT can be called to specify which cursor is to be used for a given SQL statement. Creating multiple cursors using this command allows multiple SQL statements to be opened at once. Optionally a different server can be specified for each cursor by passing the server name to this command as well. If no server is specified, the current server will be used. Note that it is important to close all cursors at the end using SQL_CLOSE_CURSOR_STMT.
Syntax
SQL_OPEN_CURSOR_STMT [of {server}] to {variable}
Parameter |
Description |
---|---|
server |
Name of the server (optional) |
variable |
Variable to hold the returned cursor handle |
Example
Integer iCursor1 iCursor2 iCustomer
String sName
Number nOrderTotal
SQL_OPEN_CURSOR_STMT to iCursor1
SQL_SET_STMT to "SELECT CUSTOMER_NUMBER,NAME FROM CUSTOMER "
SQL_APPEND_STMT to "ORDER BY NAME "
SQL_PREPARE_STMT
SQL_EXECUTE_STMT
Repeat
SQL_SET_CURRENT_CURSOR_STMT TO iCursor1
SQL_FETCH_NEXT_ROW INTO iCustomer sName
If (Found) Begin
SQL_OPEN_CURSOR_STMT to iCursor2
SQL_SET_STMT to "SELECT SUM(ORDER_TOTAL) FROM ORDERHEA "
SQL_APPEND_STMT to ("WHERE CUSTOMER_NUMBER = " + Trim(iCustomer))
SQL_PREPARE_STMT
SQL_EXECUTE_STMT
SQL_FETCH_NEXT_ROW INTO nOrderTotal
If (Found and nOrderTotal > 0) Begin
Showln "Customer : " iCustomer "-" sName " - Total: " nOrderTotal
End
SQL_CLOSE_CURSOR_STMT to Cursor2
Indicate Found True
End
Until (Not(Found))
SQL_CLOSE_CURSOR_STMT to Cursor1