OdbcAlloc Function

Action

Allocates memory for a connection, environment or descriptor handle.

Include file

ODBC.bdh

Syntax

OdbcAlloc( in nType    : number,
           out hHandle : number,
           in hParent  : number optional ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
nType

Type of the handle to be allocated. This parameter must be one of the following:

  • SQL_HANDLE_ENV. Environment handle.

  • SQL_HANDLE_DBC. Connection handle.

  • SQL_HANDLE_DESC. Descriptor handle.

hHandle Variable receiving the handle.
hParent

Existing handle in whose context the new handle is to be allocated.

  • To allocate a connection handle, this parameter must be an environment handle that refers to a previously allocated environment information storage buffer.

  • To allocate a descriptor handle, this parameter must be a connection handle.

  • To allocate an environment handle, omit this parameter.

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 (?, ?);