SQL_FETCH action


Function

The action reads one or more lines of the result of an SQL command prepared by the SQL_PREPARE action and optionally parameterized by the SQL_BINDIN action.

Declaration
 SQL_FETCH

handleIdent_Int, retCodeIdent_Int [, maxRowsIdent_Int]

Parameters
handleIdent_IntinIdentifier - the unique number (handle) of a connection.
retCodeIdent_IntoutReturn code identifier.
maxRowsIdent_IntinIdentifier of the Int type - number of rows read at once (if not specified, the 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 SQL_PREPARE action.
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.
The maximum number of returned rows is limited by a Database configuration parameter Maximum returned rows. If the number of available rows exceeds this limit, the local structure _locVarRecordIdent specified as the 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 pages:

Napíšte komentár