Small, Fast, Reliable.
Choose any three.

About Sitemap Documentation Download License News Developers Support

## SQLite C Interface

### One-Step Query Execution Interface

>     int sqlite3_exec(
>       sqlite3*,                                  /* An open database */
>       const char *sql,                           /* SQL to be evaluted */
>       int (*callback)(void*,int,char**,char**),  /* Callback function */
>       void *,                                    /* 1st argument to callback */
>       char **errmsg                              /* Error msg written here */
>     );

This interface is used to do a one-time evaluatation of zero or more SQL statements. UTF-8 text of the SQL statements to be evaluted is passed in as the second parameter. The statements are prepared one by one using sqlite3_prepare(), evaluated using sqlite3_step(), then destroyed using sqlite3_finalize().

If one or more of the SQL statements are queries, then the callback function specified by the 3rd parameter is invoked once for each row of the query result. This callback should normally return 0. If the callback returns a non-zero value then the query is aborted, all subsequent SQL statements are skipped and the sqlite3_exec() function returns the SQLITE_ABORT.

The 4th parameter to this interface is an arbitrary pointer that is passed through to the callback function as its first parameter.

The 2nd parameter to the callback function is the number of columns in the query result. The 3rd parameter to the callback is an array of strings holding the values for each column as extracted using sqlite3_column_text(). The 4th parameter to the callback is an array of strings obtained using sqlite3_column_name() and holding the names of each column.

The callback function may be NULL, even for queries. A NULL callback is not an error. It just means that no callback will be invoked.

If an error occurs while parsing or evaluating the SQL (but not while executing the callback) then an appropriate error message is written into memory obtained from sqlite3_malloc() and *errmsg is made to point to that message. The calling function is responsible for freeing the memory using sqlite3_free(). If errmsg==NULL, then no error message is ever written.

The return value is is SQLITE_OK if there are no errors and some other return code if there is an error. The particular return value depends on the type of error.

See also lists of Objects, Constants, and Functions.

This page last modified 2007/11/22 00:41:31 UTC