f2s_esql_row_count

Applies to: Oracle, MS SQL is Not Available in Beta, MySql/MariaDB, PostgreSQL Drivers

Syntax

f2s_esql_row_count {variable} [using {variant}]

Parameter

Description

variable

The integer variable for the returned row count from the SQL result set

variant

Optional variant type variable that will receive a statement interface

Description

This command returns the row count from the executed SQL statement.

The optional “using” syntax allows you to pass around the interface created by this command. The variable passed MUST be a variant. This allows for multiple statements to be active concurrently in some cases. If you use the “using” syntax, it must be used on all subsequent commands. Mixing the using syntax is not supported. So for instance, if you plan on having multiple statements active concurrently, all active statements must make use of the using syntax.

Note

The Oracle driver instantiation of this command behaves differently than the other drivers. The Oracle driver uses a non-scrollable or forward-only cursor. This type of cursor fetches rows in sequential order, starting from the first row and moving to the end. The cursor does not change direction (it cannot go backwards or jump rows) within the result set. There are two consequences to this behaviour

  • f2s_esql_row_count must be called AFTER the rows are fetched to give an accurate count. If called before or if the rows are not fetched, it will return 0.

  • f2s_esql_row_count will return the number of affected rows from an UPDATE/DELTE statement.

Example

     Variant vStat
     Variant[] vRow
     String sVal
     Integer iResultSetRowCount

     f2s_esql_create_stmt "Select * from sys.databases" using vStat
     f2s_esql_set_cursor_type f2s_olecursor_server using vStat
     f2s_esql_prepare_stmt using vStat

     f2s_esql_execute_stmt using vStat
     f2s_esql_row_count iResultSetRowCount using vStat
     Showln "Number of sys.databases returned = " iResultSetRowCount

     f2s_esql_close_stmt using vStat
     inkey windowIndex

Example using the Oracle Driver

     Variant[][] vRow
     String sVal
     Integer iResultSetRowCount iCount

     f2s_esql_create_stmt "Select * from CUSTOMER"
     f2s_esql_prepare_stmt

     f2s_esql_execute_stmt

     //iResultSetRowCount will be 0
     f2s_esql_row_count iResultSetRowCount
     Showln "Number of customer records returned = " iResultSetRowCount

     f2s_esql_close_stmt

     //this time, retrieve the data
     f2s_esql_create_stmt "Select * from CUSTOMER"
     f2s_esql_prepare_stmt
     f2s_esql_execute_stmt
     f2s_esql_move_next
     While (Found)
         f2s_esql_get_row vRow[iCount]
         Increment iCount
         f2s_esql_move_next
     Loop
     //iResultSetRowCount will be the number of records read in
     f2s_esql_row_count iResultSetRowCount
     Showln "Number of customer records returned = " iResultSetRowCount
     f2s_esql_close_stmt

Replaces

SQL_GET_NUM_ROWS