dbExecuteCommand()
Database function for executing a database manipulation command.
Synopsis
int dbExecuteCommand( dbCommand command[, dbRecordset
rs]);
Parameters
Parameter | Meaning |
---|---|
command | Command reference provided by dbStartCommand(). |
rs |
Optional recordset parameter as names/values pair which was set with dbSetParameter(). It allows executing queries which require so-called bind parameters. Note: If this parameter is used, it must be closed explicitly in the script (see example 2 below). |
Return Value
The return value is an error code; 0 indicates the operation has been performed successfully. For other values dbGetError() can be used to obtain detailed error information.
Errors
An error is returned if an invalid command reference is passed, or for commands that are not permitted (passed with dbStartCommand()).
Description
dbExecuteCommand() executes a command object previously created with dbStartCommand(). Repeated execution of one and the same command object (without repeated dbStartCommand()) is supported. In addition, so-called bind parameters can be passed to the command execution in the optional parameter rs. These must be set before with dbSetParameter().
Bind parameters cannot be used to edit zero values (insert / update / delete)!
Example 1
Example 2
DebugN("SetParamTest");
if (dbOpenConnection(sConnectString, dbConn) == 0 &&
anytype fld; string sql = "SELECT a FROM ado_test WHERE B = :1 OR B = :2"; rc = dbStartCommand(dbConn, sql, dbCmd); rc = dbSetParameter(dbCmd, 2, DB_PARAM_IN, 255); rc = dbSetParameter(dbCmd, 1, DB_PARAM_IN, 23); rc = dbExecuteCommand(dbCmd, rs2); while(!rc && !dbEOF rs2)) // As long as end of file not reached { rc = dbGetField(rs2, 0, fld); // Current column DebugN("out(1): ", fld); rc = dbMoveNext(rs2);// Go to next record set } dbCloseRecordset(rs2);// Close subset // Change parameters rc = dbSetParameter(dbCmd, 1, DB_PARAM_IN, 47); rc = dbSetParameter(dbCmd, 2, DB_PARAM_IN, 255); rc = dbExecuteCommand(dbCmd, rs); while (!rc && !dbEOF (rs)) { rc = dbGetField(rs, 0, fld);// Current column DebugN("out(2): ", fld ); rc = dbMoveNext(rs);// Go to next record set } dbCloseRecordset(rs); // Close subset DebugN("test complete, committing and closing database connection"); dbCommitTransaction(dbConn); dbCloseConnection(dbConn);
exit(0); } |
Assignment
ADO and Qt, Database functions
Availability
CTRL