Execute an SQL
insert,updateordeletestatement with ava_listargument containing a list of parameters or an array of Value parameters.For an overview see page McoSqlEngine
Prototypes
int64_t SqlEngine::vexecuteStatement(char const* sql, va_list* list); int64_t SqlEngine::vexecuteStatement(char const* sql, Value** params); int64_t SqlEngine::vexecuteStatement(char const* sql, Value** params, size_t nParams); int64_t SqlEngine::vexecuteStatement(Transaction* trans, char const* sql, va_list* list); int64_t SqlEngine::vexecuteStatement(Transaction* trans, char const* sql, Value** params); int64_t SqlEngine::vexecuteStatement(Transaction* trans, char const* sql, Value** params, size_t nParams);Arguments
transA Transaction instance. When passed, no implicit database transaction is started or committed. When absent, the SQL statement is executed within an implicit database transaction.sqlA string containing an SQLinsert,updateordeletestatement with possible parameters to be substituted from the variable list.listAva_listargument containing a list of parameters to be substituted into thesqlstring.paramsA pointer to one or an array of Value parameters.nParamsAn integer value specifying the number of Value objects in arrayparams, or -1 if the number is unknown.Description
These methods execute an SQL
insert,updateordeletestatement with a variable list of parameters. (See page Parameter Substitution Format Specifiers.) They return an integer value indicating the number of table rows affected. The first three versions ofvexecuteStatement()start an implicit read-only database transaction and roll back the transaction when finished. When the second group of three versions ofvexecuteStatement()(with thetransparameter) are called, the statement is executed within the context of this Transaction; the calling application code is responsible for starting and committing or rolling back the Transaction.Returns
These methods return an integer value indicating the number of table rows affected, or throw a RuntimeException in the case of an error.
Example
const char * dbname = "SqlDb"; int main(int argc, char* argv[]) { McoSqlEngine engine; ... engine.open(dbname, // database name SqlDb_get_dictionary(), // database dictionary DATABASE_SIZE, // database size MEMORY_PAGE_SIZE, // page size MAP_ADDRESS); // mapping address for shared memory mode ... DoSql(trans, "insert into Person(name) values('%s')", "Thomas"); ... } void DoSql(Transaction* trans, const char * sql, ...) { va_list list; int64_t rc; va_start(list, sql); rc = engine.vexecuteStatement(trans, sql, &list); va_end(list); ... }