Execute an SQL
selectstatement with ava_listargument containing a list of parameters or an array of Value parameters.For an overview see page McoSqlEngine
Prototypes
ResultSet* SqlEngine::vexecuteQuery(char const* sql, va_list* list); ResultSet* SqlEngine::vexecuteQuery(char const* sql, Value** params); ResultSet* SqlEngine::vexecuteQuery(char const* sql, Value** params, size_t nParams); ResultSet* SqlEngine::vexecuteQuery(Transaction* trans, char const* sql, va_list* list); ResultSet* SqlEngine::vexecuteQuery(Transaction* trans, char const* sql, Value** params); ResultSet* SqlEngine::vexecuteQuery(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 SQLselectstatement is executed within an implicit database transaction.sqlA string containing an SQLselectstatement 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
selectstatement with a variable list of parameters. (See page Parameter Substitution Format Specifiers.) They return a QueryResult containing the set of table rows that satisfy the query. The first three versions ofvexecuteQuery()start an implicit read-only database transaction and roll back the transaction when finished. When the second group of three versions ofvexecuteQuery()(with thetransparameter) are called, the query 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 a QueryResult 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 ... Query(trans, "select * from Person where name like %s", "Thomas"); ... } void Query(Transaction* trans, const char * sql, ...) { va_list list; va_start(list, sql); QueryResult result(engine.vexecuteQuery(trans, sql, &list)); va_end(list); ... }