Initialize a precompiled statement
#include <qdb/qdb.h> int qdb_stmt_init( qdb_hdl_t *hdl, const char *sql, uint32_t len)
qdb
This function initializes a prepared (precompiled) SQL statement. A prepared statement is compiled once, and can be executed multiple times (with calls to qdb_stmt_exec()). This function returns a statement ID for the precompiled statement, which you need to pass in to qdb_stmt_exec().
QDB executes precompiled statements faster than uncompiled statements, so this approach can optimize your application's performance when executing frequently used statements.
You can free precompiled statements using qdb_stmt_free(), although all precompiled statements are freed when you call qdb_disconnect().
The following code snippet shows how to compile, execute, and free an SQL statement:
int stmtid; qdb_binding_t qbind[2]; uint64_t msid, limit; const char *sql = "SELECT fid FROM library WHERE msid=?1 LIMIT ?2;"; stmtid = qdb_stmt_init(db, sql, strlen(sql)+1); if (stmtid == -1) { // Could not compile return -1; } msid = 1; limit = 10; QDB_SETBIND_INT(&qbind[0], 1, msid); QDB_SETBIND_INT(&qbind[1], 2, limit); if (qdb_stmt_exec(db, stmtid, qbind, 2) == -1) { // Could not execute return -1; } qdb_stmt_free(db, stmtid);
QNX Neutrino
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |