Conformance
Version Introduced: ODBC 1.0
Standards Compliance: ISO 92
Summary
f90SQLExecute executes a prepared statement, using the current values of the parameter marker variables if any parameter markers exist in the statement.
Syntax
| f90SQLExecute | (StatementHandle, iRet) |
| integer(SQLHSTMT_KIND),intent(in):: | StatementHandle |
| integer(SQLRETURN_KIND),intent(out):: | iRet |
Arguments
StatementHandle [Input]
Statement handle.
iRet [Output]
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NEED_DATA, SQL_STILL_EXECUTING, SQL_ERROR, SQL_NO_DATA, or SQL_INVALID_HANDLE.
Diagnostics
When f90SQLExecute returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value can be obtained by calling f90SQLGetDiagRec with a HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle. The following table lists the SQLSTATE values commonly returned by f90SQLExecute and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
| SQLSTATE | Error | Description |
| 01000 | General warning | Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
| 01001 | Cursor operation conflict | The prepared statement associated with the StatementHandle
contained a positioned update or delete statement, and no rows or more than one row were
updated or deleted. (For more information about updates to more than one row, see the description of the SQL_ATTR_SIMULATE_CURSOR Attribute in f90SQLSetStmtAttr.) (Function returns SQL_SUCCESS_WITH_INFO.) |
| 01003 | NULL value eliminated in set function | The prepared statement associated with StatementHandle contained a set function (such as AVG, MAX, MIN, and so on), but not the COUNT set function, and NULL argument values were eliminated before the function was applied. (Function returns SQL_SUCCESS_WITH_INFO.) |
| 01004 | String data, right truncated | String or binary data returned for an output parameter resulted in the truncation of non-blank character or non-NULL binary data. If it was a string value, it was right-truncated. (Function returns SQL_SUCCESS_WITH_INFO.) |
| 01006 | Privilege not revoked | The prepared statement associated with the StatementHandle was a REVOKE statement and the user did not have the specified privilege. (Function returns SQL_SUCCESS_WITH_INFO.) |
| 01007 | Privilege not granted | The prepared statement associated with the StatementHandle was a GRANT statement and the user could not be granted the specified privilege. |
| 01S02 | Option value changed | A specified statement attribute was invalid
because of implementation working conditions, so a similar value was temporarily
substituted. (f90SQLGetStmtAttr can be called to
determine what the temporarily substituted value is.) The substitute value is valid for
the StatementHandle until the cursor is closed, at which point the statement
attribute reverts to its previous value. The statement attributes that can be changed are:
SQL_ATTR_CONCURRENCY, SQL_ATTR_CURSOR_TYPE, SQL_ATTR_KEYSET_SIZE, SQL_ATTR_MAX_LENGTH, SQL_ATTR_MAX_ROWS, SQL_ATTR_QUERY_TIMEOUT, and SQL_ATTR_SIMULATE_CURSOR. (Function returns SQL_SUCCESS_WITH_INFO.) |
| 01S07 | Fractional truncation | The data returned for an input/output or
output parameter was truncated such that the fractional part of a numeric data type was
truncated or the fractional portion of the time component of a time, timestamp, or
interval data type was truncated. (Function returns SQL_SUCCESS_WITH_INFO.) |
| 07002 | COUNT field incorrect | The number of parameters specified in f90SQLBindParameter was less than the number of parameters in the SQL statement contained in StatementText. f90SQLBindParameter was called with ParameterValuePtr set to a null pointer, StrLen_or_IndPtr not set to SQL_NULL_DATA or SQL_DATA_AT_EXEC, and InputOutputType not set to SQL_PARAM_OUTPUT, so that the number of parameters specified in f90SQLBindParameter was greater than the number of parameters in the SQL statement contained in StatementText. |
| 07006 | Restricted data type attribute violation | The data value identified by the ValueType
argument in f90SQLBindParameter for the bound
parameter could not be converted to the data type identified by the ParameterType
argument in f90SQLBindParameter. The data value
returned for a parameter bound as SQL_PARAM_INPUT_OUTPUT or SQL_PARAM_OUTPUT could not be
converted to the data type identified by the ValueType argument in f90SQLBindParameter. (If the data values for one or more rows could not be converted, but one or more rows were successfully returned, this function returns SQL_SUCCESS_WITH_INFO.) |
| 07S01 | Invalid use of default parameter | A parameter value, set with f90SQLBindParameter, was SQL_DEFAULT_PARAM, and the corresponding parameter was not a parameter for an ODBC canonical procedure invocation. |
| 08S01 | Communication link failure | The communication link between the driver and the data source to which the driver was connected failed before the function completed processing. |
| 21S02 | Degree of derived table does not match column list | The prepared statement associated with the StatementHandle contained a CREATE VIEW statement, and the unqualified column list (the number of columns specified for the view in the column-identifier arguments of the SQL statement) contained more names than the number of columns in the derived table defined by the query-specification argument of the SQL statement. |
| 22001 | String data, right truncation | The assignment of a character or binary value to a column resulted in the truncation of non-blank (character) or non-null (binary) characters or bytes. |
| 22002 | Indicator variable required but not supplied | NULL data was bound to an output parameter whose StrLen_or_IndPtr set by f90SQLBindParameter was a null pointer. |
| 22003 | Numeric value out of range | The prepared statement associated with the StatementHandle contained a bound numeric parameter and the parameter value caused the whole (as opposed to fractional) part of the number to be truncated when assigned to the associated table column. Returning a numeric value (as numeric or string) for one or more input/output or output parameters would have caused the whole (as opposed to fractional) part of the number to be truncated. |
| 22007 | Invalid datetime format | The prepared statement associated with the StatementHandle
contained an SQL statement that contained a date, time, or timestamp structure as a bound
parameter and the parameter was, respectively, an invalid date, time, or timestamp. An
input/output or output parameter was bound to a date, time, or timestamp Fortran
structure, and a value in the returned parameter was, respectively, an invalid date, time,
or timestamp. (Function returns SQL_SUCCESS_WITH_INFO.) |
| 22008 | Datetime field overflow | The prepared statement associated with the StatementHandle contained an SQL statement that contained a datetime expression that, when computed, resulted in a date, time, or timestamp structure that was invalid. A datetime expression computed for an input/output or output parameter resulted in a date, time, or timestamp Fortran structure that was invalid. |
| 22012 | Division by zero | The prepared statement associated with the StatementHandle contained an arithmetic expression that caused division by zero. An arithmetic expression calculated for an input/output or output parameter resulted in division by zero. |
| 22015 | Interval field overflow | StatementText contained an exact
numeric or interval parameter that, when converted to an interval SQL data type, caused a
loss of significant digits. StatementText contained an interval parameter with more than one field that, when converted to a numeric data type in a column, had no representation in the numeric data type. StatementText contained parameter data that was assigned to an interval SQL type, and there was no representation of the value of the Fortran type in the interval SQL type. Assigning an input/output or output parameter that was an exact numeric or interval SQL type to an interval Fortran type caused a loss of significant digits. When an input/output or output parameter was assigned to an interval Fortran structure, there was no representation of the data in the interval data structure. |
| 22018 | Invalid character value for cast specification | StatementText contained a Fortran type that was an exact or approximate numeric, a datetime, or an interval data type; the SQL type of the column was a character data type; and the value in the column was not a valid literal of the bound Fortran type. When an input/output or output parameter was returned, the SQL type was an exact or approximate numeric, a datetime, or an interval data type; the Fortran type was SQL_F_CHAR; and the value in the column was not a valid literal of the bound SQL type. |
| 22019 | Invalid escape character | The prepared statement associated with StatementHandle contained a LIKE predicate with an ESCAPE in the WHERE clause, and the length of the escape character following ESCAPE was not equal to 1. |
| 22025 | Invalid escape sequence | The prepared statement associated with StatementHandle contained "LIKE pattern value ESCAPE escape character" in the WHERE clause, and the character following the escape character in the pattern value was not one of "%" or "_". |
| 23000 | Integrity constraint violation | The prepared statement associated with the StatementHandle contained a parameter. The parameter value was NULL for a column defined as NOT NULL in the associated table column, a duplicate value was supplied for a column constrained to contain only unique values, or some other integrity constraint was violated. |
| 24000 | Invalid cursor state | A cursor was positioned on the StatementHandle by f90SQLFetch or f90SQLFetchScroll. This error is returned by the Driver Manager if f90SQLFetch or f90SQLFetchScroll has not returned SQL_NO_DATA, and is returned by the driver if f90SQLFetch or f90SQLFetchScroll has returned SQL_NO_DATA. A cursor was open on the StatementHandle. The prepared statement associated with the StatementHandle contained a positioned update or delete statement and the cursor was positioned before the start of the result set or after the end of the result set. |
| 40001 | Serialization failure | The transaction was rolled back due to a resource deadlock with another transaction. |
| 40003 | Statement completion unknown | The associated connection failed during the execution of this function and the state of the transaction cannot be determined. |
| 42000 | Syntax error or access violation | The user did not have permission to execute the prepared statement associated with the StatementHandle. |
| 44000 | WITH CHECK OPTION violation | The prepared statement associated with StatementHandle contained an INSERT statement performed on a viewed table or a table derived from the viewed table which was created by specifying WITH CHECK OPTION, such that one or more rows affected by the INSERT statement will no longer be present in the viewed table. The prepared statement associated with the StatementHandle contained an UPDATE statement performed on a viewed table or a table derived from the viewed table which was created by specifying WITH CHECK OPTION, such that one or more rows affected by the UPDATE statement will no longer be present in the viewed table. |
| HY000 | General error | An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by f90SQLGetDiagRec in the MessageText buffer describes the error and its cause. |
| HY001 | Memory allocation error | The driver was unable to allocate memory required to support execution or completion of the function. |
| HY008 | Operation canceled | Asynchronous processing was enabled for the StatementHandle. The function was called and, before it completed execution, f90SQLCancel was called on the StatementHandle. Then the function was called again on the StatementHandle.The function was called and, before it completed execution, f90SQLCancel was called on the StatementHandle from a different thread in a multithread application. |
| HY010 | Function sequence error | (DM) An asynchronously executing function (not
this one) was called for the StatementHandle and was still executing when this
function was called. (DM) f90SQLExecute, f90SQLExecDirect, f90SQLBulkOperations, or f90SQLSetPos was called for the StatementHandle and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns. (DM) The StatementHandle was not prepared. |
| HY013 | Memory management error | The function call could not be processed because the underlying memory objects could not be accessed, possibly because of low memory conditions. |
| HY090 | Invalid string or buffer length | A parameter value, set with f90SQLBindParameter, was a null pointer and the parameter length value was not 0, SQL_NULL_DATA, SQL_DATA_AT_EXEC, SQL_DEFAULT_PARAM, or less than or equal to SQL_LEN_DATA_AT_EXEC_OFFSET. A parameter value, set with f90SQLBindParameter, was not a null pointer; the Fortran data type was SQL_F_BINARY or SQL_F_CHAR; and the parameter length value was less than 0, but was not SQL_NTS, SQL_NULL_DATA, SQL_DEFAULT_PARAM, or SQL_DATA_AT_EXEC, or less than or equal to SQL_LEN_DATA_AT_EXEC_OFFSET. A parameter length value bound by f90SQLBindParameter was set to SQL_DATA_AT_EXEC; the SQL type was either SQL_LONGVARCHAR, SQL_LONGVARBINARY, or a long, data source - specific data type; and the SQL_NEED_LONG_DATA_LEN information type in f90SQLGetInfo was "Y". |
| HY105 | Invalid parameter type | The value specified for the argument InputOutputType in f90SQLBindParameter was SQL_PARAM_OUTPUT, and the parameter was an input parameter. |
| HY109 | Invalid cursor position | The prepared statement was a positioned update or delete statement and the cursor was positioned (by f90SQLSetPos or f90SQLFetchScroll) on a row that had been deleted or could not be fetched. |
| HYC00 | Optional feature not implemented | The combination of the current settings of the SQL_ATTR_CONCURRENCY and SQL_ATTR_CURSOR_TYPE statement attributes was not supported by the driver or data source. The SQL_ATTR_USE_BOOKMARKS statement attribute was set to SQL_UB_VARIABLE, and the SQL_ATTR_CURSOR_TYPE statement attribute was set to a cursor type for which the driver does not support bookmarks. |
| HYT00 | Timeout expired | The query timeout period expired before the data source returned the result set. The timeout period is set through f90SQLSetStmtAttr, SQL_ATTR_QUERY_TIMEOUT. |
| HYT01 | Connection timeout expired | The connection timeout period expired before the data source responded to the request. The connection timeout period is set through f90SQLSetConnectAttr, SQL_ATTR_CONNECTION_TIMEOUT. |
| IM001 | Driver does not support this function | (DM) The driver associated with the StatementHandle does not support the function. |
f90SQLExecute can return any SQLSTATE that can be returned by f90SQLPrepare based on when the data source evaluates the SQL statement associated with the statement.
Comments
f90SQLExecute executes a statement prepared by f90SQLPrepare. After the application processes or discards the results from a call to f90SQLExecute, the application can call f90SQLExecute again with new parameter values. To execute a SELECT statement more than once, the application must call f90SQLCloseCursor before reexecuting the SELECT statement.
If the data source is in manual-commit mode (requiring explicit transaction initiation), and a transaction has not already been initiated, the driver initiates a transaction before it sends the SQL statement. If an application uses f90SQLPrepare to prepare and f90SQLExecute to submit a COMMIT or ROLLBACK statement, it will not be interoperable between DBMS products. To commit or roll back a transaction, call f90SQLEndTran.
If f90SQLExecute encounters a data-at-execution parameter, it returns SQL_NEED_DATA. The application sends the data using f90SQLParamData and f90SQLPutData.
If f90SQLExecute executes a searched update or delete statement that does not affect any rows at the data source, the call to f90SQLExecute returns SQL_NO_DATA.
If the value of the SQL_ATTR_PARAMSET_SIZE statement attribute is greater than 1, and the SQL statement contains at least one parameter marker, f90SQLExecute executes the SQL statement once for each set of parameter values in the arrays pointed to by the *ParameterValuePtr argument in the calls to f90SQLBindParameter.
If bookmarks are enabled, and a query is executed that cannot support bookmarks, then the driver should attempt to coerce the environment to one that supports bookmarks by changing an attribute value and returning SQLSTATE 01S02 (Option value changed). If the attribute cannot be changed, the driver should return SQLSTATE HY024 (Invalid attribute value).
Note: When using connection pooling, an application must not execute SQL statements that change the database or the context of the database, such as the USE database statement in SQL Server, which changes the catalog used by a data source.
Code Example
See f90SQLBindParameter, f90SQLBulkOperations, f90SQLPutData, and f90SQLSetPos.
Related Subroutines
| For information about | See |
| Binding a buffer to a column in a result set | f90SQLBindCol |
| Canceling statement processing | f90SQLCancel |
| Closing the cursor | f90SQLCloseCursor |
| Executing a commit or rollback operation | f90SQLEndTran |
| Executing an SQL statement | f90SQLExecDirect |
| Fetching multiple rows of data | f90SQLFetch |
| Fetching a block of data or scrolling through a result set | f90SQLFetchScroll |
| Freeing a statement handle | f90SQLFreeStmt |
| Returning a cursor name | f90SQLGetCursorName |
| Fetching part or all of a column of data | f90SQLGetData |
| Returning the next parameter to send data for | f90SQLParamData |
| Preparing a statement for execution | f90SQLPrepare |
| Sending parameter data at execution time | f90SQLPutData |
| Setting a cursor name | f90SQLSetCursorName |
| Setting a statement attribute | f90SQLSetStmtAttr |