string comparison, lexical analysis, the store of the symbol table in the grammar analysis as well
as the professional printing function and the random number function of SQLite. More than half
of the SQLite functions can be debugged with the test code and it simulates the recovery
mechanism of SQLite when the system collapses.
Embedded database SQLite provides API interface of C language, making operation of the
database is very simple. Some of the functions will be introduced briefly in the following paper
[4]
:
1) C/C++ common interface of SQLite3
typedef struct sqlite3 sqlite3;
int sqlite3_open(const char*, sqlite3**); //open the database, including documents and
memory database.
int sqlite3_close(sqlite3*); //close the database
int qlite3_last_insert_rowid(sqlite3*); //the line of inserting data finally
const char *sqlite3_errmsg(sqlite3*); //get the corresponding introduction of error code. These
error messages will be returned in UTF-8, and will be removed when it calls any SQLite API
function next time.
int sqlite3_errcode(sqlite3*); // acquire the error code that calls the recent API interface.
2) Different implementation ways of SQLite3
• Implement one or more lines of SQL statements andimplement the callback function on the
each line ofquerying results: int sqlite3_exec();
• Structure the SQL statement dynamically:
char *sqlite3_mprintf(const char*,...);
char *sqlite3_vmprintf(const char*, va_list);
//structure statements,executed by sqlite3_exec
int sqlite3_exec_printf();
//structure querying statements and execute void
Figure 1. Internal structure of SQLite.
sqlite3_free(char *z);// release the memory allocated
by sqlite3_ (v)
• Pre-compile SQL statement, reduce the time of SQL
analysis:
int sqlite3_prepare();// pre-compile
int sqlite3_step(sqlite3_stmt*); //execute once or
more
int sqlite3_reset ( sqlite3_ stmt*);
//reset sqlite3_stmt(come from sqlite3_prepare())
int sqlite3_finalize(sqlite3_stmt *pstmt); //release