OdbcFetch Function

Action

Performs a specified number of fetch operations in order to retrieve data from a SQL query. This function is used to fetch both single and multiple rows. It can be called only while a result data set exists. That is, after a SQL statement that creates a result set is executed and before the cursor associated with that result data is closed.

Include file

ODBC.bdh

Syntax

OdbcFetch( in  cCursor     : cursor,
           in  nIterations : number optional,
           in  nArraySize  : number optional,
           in  nDirection  : number optional,
           in  nOption     : number optional,
           in  nBookmark   : number optional,
           out nFetched    : number optional ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
cCursor Cursor associated with a database connection.
nIterations

Number of iterations to perform (optional). Predefined options are:

  • SQL_FETCH_ALL. Repeat the fetch operation until all rows have been fetched

The default option is to perform a single iteration

nArraySize Number of rows to fetch per iteration (optional). The default option is to fetch a single row per iteration.
nDirection

Specifies the direction and type of fetch to perform (optional). This parameter must be set to one of the following values:

  • SQL_FETCH_NEXT

  • SQL_FETCH_FIRST

  • SQL_FETCH_LAST

  • SQL_FETCH_PRIOR

  • SQL_FETCH_ABSOLUTE

  • SQL_FETCH_RELATIVE

  • SQL_FETCH_RESUME

  • SQL_FETCH_BOOKMARK

nOption Ordinal position of the first row in the row set to fetch (optional).
nBookmark Bookmark value used to identify a row of data (optional).
nFetched Variable receiving the actual number of rows fetched (optional).

Example

var
  hEnv, hDbc : number;
  c1, c2 : cursor;

dcltrans
  transaction TMain
  begin
    OdbcAlloc(SQL_HANDLE_ENV, hEnv);
    OdbcAlloc(SQL_HANDLE_DBC, hDbc, hEnv);
    OdbcConnect(hDbc, "DSN=database;UID=user;PWD=pass;");
    OdbcOpen(c1, hDbc);
    OdbcPrepare(c1, sqlSelect);
    OdbcSetCursorName(c1, "cursor_persons");
    OdbcExecute(c1);
    OdbcFetch(c1);
    OdbcOpen(c2, hDbc);
    OdbcPrepare(c2, sqlDelete);
    OdbcExecute(c2);
    OdbcClose(c1, SQL_DROP);
    OdbcClose(c2, SQL_DROP);
    OdbcCommit(hDbc);
    OdbcDisconnect(hDbc);
    OdbcFree(hDbc);
    OdbcFree(hEnv);
  end TMain;

dclsql
  sqlSelect:
    SELECT * FROM persons;
  sqlDelete:
    DELETE FROM persons WHERE CURRENT OF cursor_persons;