qdb_statement()

Execute SQL code on a database

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. This 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. For information on these two additional specifiers, 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 executing 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, the function might return before the SQL code completes execution but might not report errors. In this case, you must 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