C. API function of SQLite
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 and
implement the callback function on the each line of
querying 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
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
• Make use of the encapsulation about sqlite3_exec ()
and return all results:
int sqlite3_get_table();
void sqlite3_free_table(char **result);