An SQLDBC_Statement is a class for executing SQL statements immediately.
With this class applications can handle all DDL and DML commands without parameter markers. Parameter markers are the '?' or ':<name>' tags. Use SQLDBC_Connection::createStatement from the connection object to get a new SQLDBC_Statement object.
Use the execute() member function to execute the SQL statement.
The SQL statement may contain ASCII or UCS2 characters and must not be zero-terminated. The execute() member function converts it automatically to the correct code set according to the encoding of the database. In this way it is possible to write portable code for UNICODE and non-UNICODE databases. To increase performance, applications should use UCS2 statements only for UNICODE databases.
Example:
Execution of a SQL statement
SQLDBC_Statement *stmt = conn->createStatement();
SQLDBC_Retcode rc = stmt->execute("SELECT * FROM DUAL");
if (rc != SQLDBC_OK) {
Handle error ...
}
After execution, the application must check the return code of the command. If an SQL error occurred the error() member function returns error details.
Query statements like SELECT or CALL DBPROC commands may produce a result set. Applications should check this with the isQuery() or getResultSet() member function.
The getResultSet() member function returns a reference to an SQLDBC_ResultSet object. Applications can use SQLDBC_ResultSet for retrieving data from the result set of the query statement or to navigate within result sets. An opened result set is automatically closed by reusing the execute() member function or by closing the object with an SQLDBC_Connection::releaseStatement().
Prior to executing an SQL statement, the application can set the name of the result set with the setCursorName() member function, or it can set the type of the result set with setResultSetType() to modify the behavior of the result set.
For non-query SQL statements the application can check the number of modified rows with the getRowsAffected() member function.
Executes an ASCII coded zero-terminated SQL statement.
The SQL statement is executed immediately on sending a DBS request to the database. In case of an error, the SQLDBC_ErrorHndl object (to be queried using error()) of this object is set. If the executed SQL statement is a query, a result set is created. The application can check this using isQuery(), and obtain retrieve the resultset using getResultSet().
Parameters:
sql
The zero-terminated ASCII coded SQL statement to be execute.
Executes an UNICODE/ASCII coded zero-terminated SQL statement.
The SQL statement is executed immediately on sending a DBS request to the database. In case of an error, the SQLDBC_ErrorHndl object (to be queried using error()) of this object is set. If the executed SQL statement is a query, a result set is created. The application can check this using isQuery(), and obtain retrieve the resultset using getResultSet().
Parameters:
sql
The zero-terminated SQL statement to be executed. The coding of this string argument depends from the encoding argument.
The SQL statement is executed immediately on sending a DBS request to the database. In case of an error, the SQLDBC_ErrorHndl object (to be queried using error()) of this object is set. If the executed SQL statement is a query, a result set is created. The application can check this using isQuery(), and obtain retrieve the ResultSet using getResultSet().
Parameters:
sql
The SQL statement to be executed. The coding of this string argument depends from the encoding argument.
The buffer into which the zero-terminated cursor name is copied.
encoding
Encoding of the buffer where the cursor name is stored.
bufferSize
Maximum size of the buffer in bytes.
bufferLength
[out] Number of bytes copied to the buffer, except the number of bytes necessary for the zero-terminator. If the source string exceeds the bufferSize. SQLDBC_DATA_TRUNC will be returned and the bufferLength set to the number of bytes (except terminator bytes) needed to copy without truncation.
Retrieves the key that was inserted by the last insert operation.
Parameters:
tag
The tag that describes whether to get the last or the first serial key. One of SQLDBC_FIRST_INSERTED_SERIAL, SQLDBC_LAST_INSERTED_SERIAL.
type
The output host type.
paramAddr
The parameter address.
lengthIndicator
The length or indicator value.
size
The size of the output parameter, in bytes.
terminate
Whether output strings are terminated. Default is SQLDBC_TRUE.
Returns:
SQLDBC_OK, if the value is returned, SQLDBC_NOT_OK if an error is set, SQLDBC_NO_DATA_FOUND if the statement didn't inserted any key, or didn't report them to the interface.
If the requested result set type isn't allowed for this SQL statement, the SQLDBC changes it to an allowed one. Check this with getResultSetType() if the execute() member function returns with a warning.
Returns the number of rows affected by the executed SQL statement.
This method returns a non-zero value if more than one row was addressed by the SQL statement. If the return value is lower than zero, more than one rows was addressed but the exact number of addressed rows cannot be determined.
Retrieves the table name (for SELECT FOR UPDATE commands).
Parameters:
buffer
The buffer in which into the table name is copied.
encoding
Encoding of the buffer where the table name is stored.
bufferSize
Size (in bytes) of the buffer
bufferLength
[out] Number of bytes copied to the buffer, except the number of bytes necessary for the zero-terminator. If the source string exceeds the bufferSize value SQLDBC_DATA_TRUNC will be returned and the bufferLength set to the number of bytes (except the terminator bytes) needed to copy the table name without truncation.
Sets the command info and a line number (for example name of programm and current line number). This will be send to the database kernel as part of a parse order. If the kernel runs in a special diagnose mode these information will be stored in a system table and can be used to profile your application. The column info and line number will be unset after the next execute of a SQL statement at this statement handle.
Parameters:
buffer
The command info.
bufferLength
Length in bytes of the buffer. In case a zero-terminated string passed on in the buffer argument, you can set the bufferLength to SQLDBC_NTS. Set bufferLength to SQLDBC_NULL_DATA if you want to unset the command info and line number.
Setting the cursorname affects only query and database procedure commands. For DDL-, INSERT-, UPDATE- and DELETE- commands setting the cursorname has no effect.
Parameters:
buffer
The new cursor name.
bufferLength
Length in bytes of the buffer. In case a zero-terminated string passed on in the buffer argument, you can set the bufferLength to SQLDBC_NTS.
The number of rows of the result set is truncated if the result of a query statement is larger than this limit. The default setting is 'unlimited' (0). Setting this limit does not affect an already executed SQL statement.
Sets the maximum number of be rows that can be fetched at once.
Sets the maximum number of rows to be fetched from a result set. Use this to manipulate the number of rows in the order interface. Use a value > 0 to set the maximum number of rows. Use a value <= 0 to reset this limit to the default value. The default value is 'unlimited' (32767). Setting this value does not affect an already executed SQL statement.