SQLite

The non-callback API provides an alternative way to retrieve data from a SQLite database by compiling an SQL statement into a virtual machine of type sqlite_vm:

typedef struct sqlite_vm sqlite_vm;

Creating a Virtual Machine

You can create a SQLite virtual machine as follows:

int sqlite_compile( sqlite *db, /* The open database */ const char *zSql, /* SQL statement to be compiled */ const char **pzTail, /* OUT: uncompiled tail of zSql */ sqlite_vm **ppVm, /* OUT: the virtual machine to execute zSql */ char **pzErrmsg /* OUT: Error message. */ );

The return code from sqlite_compile() is SQLITE_OK if the operation is successful; otherwise, one of the error codes listed in the preceding example is returned.

Step-by-Step Execution of an SQL Statement

Each invocation of sqlite_step() for a virtual machine, except the last one, returns a single row of the result:

int sqlite_step( sqlite_vm *pVm, /* The virtual machine to execute */ int *pN, /* OUT: Number of columns in result */ const char ***pazValue, /* OUT: Column data */ const char ***pazColName /* OUT: Column names and datatypes */ ); int sqlite_finalize( sqlite_vm *pVm, /* The virtual machine to be finalized */ char **pzErrMsg /* OUT: Error message */ );

Return Codes

The return code from sqlite_step() can be SQLITE_BUSY, SQLITE_ERROR, SQLITE_MISUSE, or either of the following.

#define SQLITE_ROW 100 /* sqlite_step() has another row ready */

Indicates that another row of result data is available.

#define SQLITE_DONE 101 /* sqlite_step() has finished executing */

Indicates that the SQL statement has been completely executed and sqlite_finalize() should now be called.

The return code from sqlite_finalize() indicates the overall success of the SQL command and will be the same as if the query had been executed using sqlite_exec().

    Категории