qdb_statement()

Execute an SQL statement

Synopsis:

#include <qdb/qdb.h>

int qdb_statement( qdb_hdt_t *db,
                   const char *format, ... );

Arguments:

db
A pointer to the database handle.
format
A pointer to a formatting string to process. The formatting string determines what additional arguments you need to provide. The string that results from combining format and the additional arguments is executed as SQL code on the database.

Library:

qdb

Description:

This function combines the formatting string in format with the values of the additional arguments to construct an SQL command string and then executes that string on the database referred to by db.

Individual statements within the command string must be completed with and separated by semicolons. There's no length restriction for the command string.

The formatting string and additional arguments work in the same way as with printf() (all the same conversion specifiers apply). There are additional conversion specifiers, %q and %Q, which in general should be used instead of %s for inserting text into a literal string. The %q specifier properly escapes special characters for SQL. For more information, see qdb_mprintf().

To determine how many rows were affected by the SQL command string, you can call qdb_rowchanges() after executing the command string.

Note: Because qdb_rowchanges() returns the number of rows affected by only the last SQL statement executed by qdb_statement(), we recommend defining only one statement in each qdb_statement() call; otherwise, if there's an issue, you won't be able to determine which statement failed.

By default, the SQL code is executed on the database before qdb_statement() returns. However, if the connection is in asynchronous mode, this function may return before the SQL code completes execution and may not report errors. In this case, you need to call qdb_getresult() to retrieve any errors.

Returns:

>=0
Success.
-1
An error occurred (errno is set).

Classification:

QNX Neutrino

Safety:  
Interrupt handler No
Signal handler No
Thread Yes