Skip to content

SQLExecute

SQLExecute#

SQLExecute submits a prepared statement, using the current values of the parameter marker variables if any parameter markers exist in the statement.

Syntax#

SQLRETURN  SQLExecute (
    SQLHSTMT      stmt );

Arguments#

Data Type Argument In/Output Description
SQLHSTMT stmt Input Statement handle

Return Values#

SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_NO_DATA
SQL_INVALID_HANDLE
SQL_ERROR

Description#

The parameter marker can be included in a SQL statement string. The parameter marker specified by '?' and designates the place of the parameters to be replaced as an application variable when SQLExecute() is called. SQLBindParameter() must bind each parameter marker with a corresponding application variable, and displays whether the data must be converted for transmission. All parameters must be bound before SQLExecute() is called.

SQLExecute() executes a statement prepared by SQLPrepare(). After the application processes or discards the results from a call to SQLExecute, the application can call SQLExecute() again with new parameter values.

The command executed by SQLExecDirect() cannot be execute again by SQLExecute(). SQLPrepare() must be called first.

In case SQLExecute() executes an UPDATE and DELETE statement that does not affect any row in the database, calling SQLExecute() will return SQL_NO_DATA. Use SQLRowCount() to check the number of record.

If SQL_ATTR_PARAMSET_SIZE statement attribute is higher than 1 and the SQL statement has at least one parameter marker, SQLExecute() will execute a SQL statement once for a series of the parameters in the array indicated by the *Value argument upon calling of SQLBindParameter().

Diagnosis#

SQLSTATE Description Comments
07006 Restricted data type attribute violation The column data within the result set must not be converted to the data type expressed in cType of SQLBindCol().
08003 When stmt is not connected or the connection is released
08S01 Communication channel error The communication link between the driver and the database to which the driver was connected failed before the function completed processing.
HY000 General error
HY090 Invalid string or buffer length If SQLBindParameter() and the related parameters are NULL pointers, the parameter length is not 0 or SQL_NULL_DATA.
If the parameter designated with SQLBindParameter() is not the NULL pointer, C data type will be SQL_C_BINARY or SQL_C_CHAR and the parameter length will be smaller than 0.

SQLExecute() can return all SQLSTATE data that are returned by SQLPrepare().

SQLBindCol
SQLEndTran
SQLExecDirect
SQLFetch
SQLFreeStmt
SQLGetData
SQLPrepare
SQLSetStmtAttr

Example#

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

See the examples of SQLBindParameter().