OdbcGetValue Function

Action

Retrieves any value either from a bound place holder of a SQL statement or from a result data column of a SQL query. Place holders and data columns are identified by number.

Include file

ODBC.bdh

Syntax

OdbcGetValue( in  cCursor     : cursor,
              in  sIdentifier : string,
              out sBuffer     : string,
              in  nBufferSize : number,
              in  nIndex      : number optional ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
cCursor Cursor associated with a database connection.
sIdentifier Identifier of the place holder or the result data column. To identify a place holder, begin this parameter with a colon.
sBuffer Variable receiving either the data assigned to the place holder or the data retrieved from a fetched row, as the case may be.
nBufferSize Size of the variable receiving the value.
nIndex Array index for the place holder or column item to be retrieved (optional). By default, this function retrieves the first item. An index greater than 1 requires the preceding OdbcFetch call to retrieve more than one data row at once by specifying the optional nArraySize parameter accordingly.

Example

var
  hEnv, hDbc : number;
  cCursor : cursor;

dcltrans
  transaction TMain
  var
    sBuffer : string;
    nLength : number;
  begin
    OdbcAlloc(SQL_HANDLE_ENV, hEnv);
    OdbcAlloc(SQL_HANDLE_DBC, hDbc, hEnv);
    OdbcConnect(hDbc, "DSN=database;UID=user;PWD=pass;");
    OdbcOpen(cCursor, hDbc);
    OdbcPrepare(cCursor, sqlSelect);
    OdbcExecute(cCursor);
    OdbcDefine(cCursor, "1", SQL_C_CHAR, 32);
    OdbcDefine(cCursor, "2", SQL_C_BINARY);
  
    while OdbcFetch(cCursor) do
      write("name: " + OdbcGetString(cCursor, "1"));
      OdbcGetValue(cCursor, "2", sBuffer, nLength);
      WriteData(sBuffer, nLength);
    end;

    OdbcClose(cCursor, SQL_DROP);
    OdbcCommit(hDbc);
    OdbcDisconnect(hDbc);
    OdbcFree(hDbc);
    OdbcFree(hEnv);
  end TMain;

dclsql
  sqlSelect:
    SELECT * FROM persons;