SQLExecDirect
SQLExecDirect#
If a SQL statement includes parameters, the given SQL statement will be directly executed using the current value of the parameter marker. When Using SQLExecDirect(), the SQL statement can be executed only once and is the fastest method to submit for an one-time execution.
SQLExecDirectW() as a Unicode string supports same execution as SQLExecDirect().
Syntax#
SQLRETURN SQLExecDirect (
SQLHSTMT stmt,
SQLCHAR * sql,
SQLINTEGER sqlLength );
Arguments#
Data Type | Argument | In/Output | Description |
---|---|---|---|
SQLHSTMT | stmt | Input | Statement handle |
SQLCHAR * | sql | Input | SQL statement to be executed |
SQLINTEGER | sqlLength | Input | The length, in bytes, of the contents of the sql argument |
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. Tthe parameter marker specified by "?" and designates the place of the parameters to be replaced as an application variable when SQLExecDirect() is called. SQLBindParameter() binds an application variable with the parameter marker, and displays whether data must be converted during data transmission. All parameters must be bound before SQLExecDirect() is called.
To select the row in the result set received from the server when a SQL statement is SELECT, the buffer must be bound by SQLBindCol() after SQLExecDirect() is successfully returned and SQLFetch() must be called to refer to the bound buffer.
If SQLExecDirect() executes an UPDATE or DELETE statement that does not affect any row, calling SQLExecDirect() will return SQL_NO_DATA. Use SQLRowCount() to check the number of affecting records
Diagnosis#
SQLSTATE | Description | Comments |
---|---|---|
08003 | stmt is not connected or disconnected | |
08S01 | Communication failure | Communication channel error |
HY000 | General error | |
HY001 | Memory allocation error | Failed to allocate the memory for the explicit handle |
HY009 | Invalid Arguments used (null pointer) | *sql is a NULL pointer |
Related Functions#
SQLBindCol
SQLEndTran
SQLExecute
SQLFetch
SQLGetData
SQLPrepare
SQLStmtAttr
Example#
< Refer to: $ALTIBASE_HOME/sample/SQLCLI/demo_ex1.cpp >
sprintf(query,"SELECT * FROM DEMO_EX1");
if (SQLExecDirect(stmt,query, SQL_NTS) != SQL_SUCCESS)
{
execute_err(dbc, stmt, query);
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}