OdbcGetString Function

Action

Retrieves a string 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

OdbcGetString(
   in cCursor     : cursor,
   in sIdentifier : string,
   in nIndex      : number optional ) : string;

Return value

Either the string assigned to the place holder or the string retrieved from a fetched row.

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.
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
  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_LONG);
   while OdbcFetch(cCursor) do
      write("name: " + OdbcGetString(cCursor, "1"));
      writeln(" age: " + (string)OdbcGetInt(cCursor, "2"));
    end;
    OdbcClose(cCursor, SQL_DROP);
    OdbcCommit(hDbc);
    OdbcDisconnect(hDbc);
    OdbcFree(hDbc);
    OdbcFree(hEnv);
  end TMain;

dclsql
  sqlSelect:
  SELECT * FROM persons;