SQL_FETCH action


Function
The action reads one or more rows prepared of the SQL command prepared by the action SQL_PREPARE and optionally parameterized by the action SQL_BINDIN.
Declaration
 SQL_FETCH
handleIdent_Int, retCodeIdent_Int [, maxRowsIdent_Int]
Parameters
handleIdent_Int in Identifier - the unique number (handle) of a connection.
retCodeIdent_Int out Return code identifier.
maxRowsIdent_Int in Identifier, which value limits the number of rows read. If is not entered, default value is 1.

Return code
The value of the parameter transHandle_Int. See the table of error codes. It is possible to get extended error information.
Description
The action reads given number of rows and assigns their values to the local variables specified by the action SQL_PREPARE.
MaxRowsIdent_Int is to be used only for the 3rd declaration type of the action SQL_PREPARE. If the value of the parameter is other than 1 for the declaration types 1, 2, or less than 1, the action generates the error _ERR_RANGE_ERROR.
Maximum number of returned rows is limited by a Database configuration parameter Maximum returned rows. If number of available rows exceeds this limit, the local structure _locVarRecordIdent specified as parameter of action SQL_PREPARE will contain first Maximum returned rows and retCodeIdent_Int will be set to error code _ERR_DATABASE_ROWS_LIMIT.

If no row has been read, the value of the parameter retCodeIdent_Int is 22 (_ERR_NO_DATA).
Example
Work with a database (actions SQL_ ...).

 INT  _handle    ; handle to database
 INT  _retCode   ; return code
 TEXT _name      ; product name
 TEXT _type      ; product type
 
 SQL_CONNECT MyDatabase, _handle, _retCode
 SQL_PREPARE _handle, _retCode, _sqlNpar BIND _name, _type
 
 DO_LOOP
   SQL_FETCH _handle, _retCode
   EXIT_LOOP _retCode #  _ERR_NO_ERROR
   ; data processing goes here
 END_LOOP
 
 SQL_FREE _handle
 SQL_DISCONNECT _handle
 

Related topics