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
trans A Transaction instance. When passed, no implicit database transaction is started or committed. When absent, the SQL selectstatement is executed within an implicit database transaction.sql A string containing an SQL selectstatement with possible parameters to be substituted from the variable listlist A va_listargument containing a list of parameters to be substituted into thesqlstringparams A pointer to one or an array of Value parameters nParams An integer value specifying the number of Value objects in array params, or -1 if the number is unknownDescription
These methods execute an SQL
selectstatement with a variable list of parameters. (See page Parameter Substitution Format Specifiers). It returns 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(db_name, // 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); ... }