Skip to content

SQLAllocStmt

SQLAllocStmt#

SQLAllocStmt allocates and initializes the memory for the SQL statements. Up to 1024 statements are allocated to one connection.

SQLAllocStmt() can be replaced by SQLAllocHandle().

Syntax#

SQLRETURN  SQLAllocStmt (
    SQLHDBC     dbc,
    SQLHSTMT *  stmt );

Arguments#

Data Type Arguments In/Output Description
SQLHDBC dbc Input Connection Handle
SQLHSTMT * stmt Output Pointer of statement handle

Arguments#

SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR

In case SQL_ERROR is returned, stmt arguments will be set as SQL_NULL_STMT. An application must set stmt arguments as SQL_NULL_STMT and calls SQLERROR().

Description#

The Altibase CLI driver relates the descriptors, results and status data with the processed SQL statements by using each statement handle. Each SQL statement must have a statement handle, but other commands can use the handles again.

When this function is called, the database connection used by the databasec must be referred to.

If the input pointer indicates the valid statement handle allocated by the previous calling of SQLAllocStmt(), the original value will be changed according to the result of this calling. As an application programming error, it is not detected by Altibase CLI driver.

Call SQLAllocEnv() before calling this function. This function must be called before other functions that have SQLPrepare(), SQLExecute(), SQLExecDirect() or statement handle as an input Arguments.

Diagnosis#

SQLSTATE Description Comments
HY000 General Error The number of stmt (1024) exceeds
HY001 Memory allocation error Failed to allocate the memory for the stmt.
HY009 Invalid Arguments used (null pointer) stmt is a NULL pointer.
HY010 Continuous function error (not connected or disconnected status) dbc is not connected or disconnected
SQLConnect
SQLFreeStmt

Example#

< Refer to: $ALTIBASE_HOME/sample/SQLCLI/demo_ex1.cpp >

/* Memory allocation for a statement */
if (SQL_ERROR == SQLAllocStmt(dbc, &stmt))
{
    printf("SQLAllocStmt error!!\n");
    return SQL_ERROR;
}