Reprint Please specify source: http://www.cnblogs.com/StartoverX/p/4660487.html
The project is used to SQLite3, a simple record.
Unlike MySQL, the SQLite3 database is based on file storage, does not need to communicate with the server process, and reads the database content directly through the API call. db files.
1. Installation
Direct Apt-get under Ubuntu: sudo apt-get install sqlite3 Libsqite3-dev
2. Data type (DataType)
SQLite3 have v basic types, namely NULL, INTEGER, REAL, TEXT, BLOB.
Null: null value.
Integer: Signed integer, stored in 1,2,3,4,6 or 8 bytes Depending on the size of the value
Real:float real types, stored in 8-byte IEEE floating-point numbers.
Text: The value is a literal string, stored using the database encoding (UTF-8,utf-16be, or utf-16le).
BLOB: Just a block of data that is stored exactly as input (that is, no change), memory chips, audio and video, etc.
3. Create a Database
The shell enters the directory that needs to create the database file, directly sqlite3 test.db can, query databases,tables with. Databases,.tables, view help with.
4.c++ API
The above is the most basic sqlite3 C + + API, and the most commonly used is Sqlite3_open (), Sqlite3_exec (), Sqlite3_close (). Sqlite3_exec () is an encapsulation of sqlite3_prepare (), Sqlite3_step (), Sqlite3_column (), and Sqlite3_finalize (), which completes the execution and return of an SQL statement. Examples are as follows:
Note that callback is a callback function for Sqlite3_exec (), and the third parameter of Sqlite3_exec () is passed into the first parameter of callback, thus enabling communication with the context.
on#include <stdio.h> Geneva#include <sqlite3.h>Geneva Geneva Static intCallbackvoid*arg,intargcChar**ARGV,Char**azcolname) { to inti; . for(i=0; i<argc; i++){ -printf"%s =%s\n", Azcolname[i], argv[i]? Argv[i]:"NULL"); , } theprintf"\ n");Ten return 0; One } A - intMainintargcChar**argv) { -Sqlite3 *db; the Char*zerrmsg =0; - intRC; - - if(argc!=3 ){ +fprintf (stderr,"Usage:%s DATABASE sql-statement\n", argv[0]); - return(1); + } Arc = Sqlite3_open (argv[1], &db); at if(RC) { -fprintf (stderr,"Can ' t Open database:%s\n", sqlite3_errmsg (db)); -sqlite3_close (db); - return(1); - } -rc = sqlite3_exec (db, argv[2], Callback,0, &zerrmsg); in if(rc!=SQLITE_OK) { -fprintf (stderr,"SQL Error:%s\n", zerrmsg); toSqlite3_free (zerrmsg); + } -sqlite3_close (db); the return 0; *}
Reference: An Introduction to the SQLite C/C + + Interface
SQLite in 5 Minutes or less
SQLite3 Simple Primer and C + + API