vexecuteStatement

Execute an SQL insert, update or delete statement with a va_list argument 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

trans
A Transaction instance. When passed, no implicit database transaction is started or committed. When absent, the SQL statement is executed within an implicit database transaction.
sql
A string containing an SQL insert, update or delete statement with possible parameters to be substituted from the variable list.
list
A va_list argument containing a list of parameters to be substituted into the sql string.
params
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 unknown.

Description

These methods execute an SQL insert, update or delete statement 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 of vexecuteStatement() start an implicit read-only database transaction and roll back the transaction when finished. When the second group of three versions of vexecuteStatement() (with the trans parameter) 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);
        ...
    }