OdbcBind Function

Action

Binds a place holder in a SQL statement. The bound place holder — identified by number — is then accessible through the OdbcSet and OdbcGet functions. This function must be called after preparing the SQL statement and before calling the OdbcSet functions.

Include file

ODBC.bdh

Syntax

OdbcBind( in cCursor      : cursor,
          in sPlaceholder : string,
          in nDataType    : number optional,
          in nSize        : number optional,
          in nSqlDataType : number optional,
          in nSqlSize     : number optional,
          in nPrecision   : number optional,
          in nParamType   : number optional ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
cCursor Cursor associated with a database connection.
sPlaceholder

Location of the place holder in the SQL statement. This parameter must include the preceding colon identifying it as a place holder.

Place holders are numbered sequentially from left to right, starting with 1, as they appear in the SQL statement.

nDataType

C language data type of the place holder (optional). This parameter must be set to one of the following values:

  • SQL_C_CHAR

  • SQL_C_SHORT

  • SQL_C_SSHORT

  • SQL_C_USHORT

  • SQL_C_LONG

  • SQL_C_SLONG

  • SQL_C_ULONG

  • SQL_C_FLOAT

  • SQL_C_DOUBLE

  • SQL_C_BIT

  • SQL_C_TINYINT

  • SQL_C_STINYINT

  • SQL_C_UTINYINT

  • SQL_C_BINARY

  • SQL_C_DATE

  • SQL_C_TIME

  • SQL_C_TIMESTAMP

  • SQL_C_SBIGINT

  • SQL_C_UBIGINT

  • SQL_C_TYPE_DATE

  • SQL_C_TYPE_TIME

  • SQL_C_TYPE_TIMESTAMP

  • SQL_C_WCHAR

  • SQL_C_NUMERIC

  • SQL_C_DEFAULT (default)

nSize Size of the C language data type in bytes (optional).
nSqlDataType

SQL data type of the place holder being bound (optional). This parameter must be set to one of the following values:

  • SQL_CHAR

  • SQL_VARCHAR

  • SQL_LONGVARCHAR

  • SQL_DECIMAL

  • SQL_NUMERIC

  • SQL_SMALLINT

  • SQL_INTEGER

  • SQL_REAL

  • SQL_FLOAT

  • SQL_DOUBLE

  • SQL_BIT

  • SQL_TINYINT

  • SQL_BIGINT

  • SQL_BINARY

  • SQL_VARBINARY

  • SQL_LONGVARBINARY

  • SQL_DATE

  • SQL_TIME

  • SQL_TIMESTAMP

  • SQL_INTERVAL_YEAR

  • SQL_INTERVAL_MONTH

  • SQL_INTERVAL_DAY

  • SQL_INTERVAL_HOUR

  • SQL_INTERVAL_MINUTE

  • SQL_INTERVAL_SECOND

  • SQL_INTERVAL_YEAR_TO_MONTH

  • SQL_INTERVAL_DAY_TO_HOUR

  • SQL_INTERVAL_DAY_TO_MINUTE

  • SQL_INTERVAL_DAY_TO_SECOND

  • SQL_INTERVAL_HOUR_TO_MINUTE

  • SQL_INTERVAL_HOUR_TO_SECOND

  • SQL_INTERVAL_MINUTE_TO_SECOND

  • SQL_TYPE_DATE

  • SQL_TYPE_TIME

  • SQL_TYPE_TIMESTAMP

  • SQL_WCHAR

  • SQL_WVARCHAR

  • SQL_WLONGVARCHAR

nSqlSize Size of the SQL data type in bytes (optional).
nPrecision Number of digits to the right of the decimal point (optional).
nParamType

Type of place holder being bound (optional). This parameter must be set to one of the following values:

  • SQL_PARAM_INPUT

  • SQL_PARAM_OUTPUT

  • SQL_PARAM_INPUT_OUTPUT

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, sqlInsert);
    OdbcBind(cCursor, ":1", SQL_C_CHAR, 32);
    OdbcBind(cCursor, ":2", SQL_C_LONG);
    OdbcSetString(cCursor, ":1", "Bob", 1);
    OdbcSetInt(cCursor, ":2", 25, 1);
    OdbcSetString(cCursor, ":1", "Marcy", 2);
    OdbcSetInt(cCursor, ":2", 33, 2);
    OdbcExecute(cCursor);
    OdbcClose(cCursor, SQL_DROP);
    OdbcCommit(hDbc);
    OdbcDisconnect(hDbc);
    OdbcFree(hDbc);
    OdbcFree(hEnv);
  end  TMain;

dclsql
  sqlInsert:
    INSERT INTO persons (name, age) VALUES (?, ?);