Original article:
1.Source codeObtain
SQLite is an embedded database with powerful functions and fast computation speed. It is encapsulated in C language and provides over 80 command interfaces, which are highly portable and easy to use.
: Http://sqlite.org/download.html
SQLite SourceCode: Sqlite-3.6.17.tar.gz
2. Port SQLite to x86 for Linux
L decompress the file
// Create a folder and place the source code in the folder.
Mkdir/work/SQLite
CP sqlite-3.6.17.tar.gz/work/SQLite
// Decompress the file
CD/work/SQLite
Tar xvzf sqlite-3.6.17.tar.gz
L Configuration
// Create an x86 directory
Mkdir sqlite_x86
// Open the file
CD sqlite-3.6.17
// Configure SQLite
./Configure -- prefix =/work/SQLite/sqlite_x86 -- disable-tcl
L compile
Make
L Installation
Make install
L test
After the installation is complete, the installation file will be installed in the/work/SQLite/sqlite_x86 directory. One is generated in the Lib, include, and bin folders, which are the library files, header file and executable file.
Here is not a bit eager to try, yes, we can test SQLite, when the file is installed, we can directly implement through the installed sqlite3.
CD sqlite_x86/bin
./Sqlite3 test. DB // open or create the test. DB database file
Create Table Test (ID integer primary key, value text );
Insert into test (value) values ('hxl ');
Insert into test (value) values ('sqlite ');
Insert into test (value) values ('test ');
Insert into test (value) values ('');
Insert into test (value) values ('linux ');
// The database is basically finished at home. Let's take a look at the files in the database.
. Mode col
. Headers on // print the database Header
Select * from test; // display all files in the database
. Exit // exit
3. Port SQLite to arm
L Configuration
// Create an x86 directory
Mkdir http://www.cnblogs.com/sqlite_arm
// Open the file
CD http://www.cnblogs.com/sqlite-3.6.17
// Configure SQLite
./Configure -- prefix =/work/SQLite/sqlite_arm -- disable-tcl-host = arm-Linux
L compile
Make
L Installation
Make install
L test
After the installation is complete, the installation file will be installed in the/work/SQLite/sqlite_x86 directory. One is generated in the Lib, include, and bin folders, which are the library files, header file and executable file.
Copy the file in lib to the Lib of the development board, and write a c file test. C to drive it.
# Include <Stdio. h> # Include <Sqlite3.h> Static Int Callback ( Void * Notused, Int Argc, Char ** Argv, Char ** Azcolname ){ Int I; For (I = 0 ; I <argc; I ++ ) {Printf ( " % S = % s \ n " , Azcolname [I], argv [I]? Argv [I]: " Null " );} Printf ( " \ N " ); Return 0 ;} Int Main ( Int Argc, Char ** Argv) {sqlite3 * DB; Char * Zerrmsg = 0 ; Int RC; If (Argc! = 3 ) {Fprintf (stderr, " Usage: % s Database SQL-STATEMENT \ n " , Argv [ 0 ]); Return ( 1 );} RC = Sqlite3_open (argv [ 1 ], & DB ); 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 ); If (RC! = Sqlite_ OK) {fprintf (stderr, " SQL error: % s \ n " , Zerrmsg); sqlite3_free (zerrmsg);} sqlite3_close (db ); Return 0 ;}
Non-embedded Compilation:
Gcc-g test. C-o Test-lsqlite3
The above code is the official test code of SQLite. Although it is very simple, it is also very powerful. Generally, the application is enough. After learning about the SQLite syntax, You can implement powerful functions. The compilation method is as follows, here assuming that you have installed arm-Linux-GCC, I am using the arm-linux-gcc-4.3.2, the compilation method is as follows:
Arm-Linux-gcc-O test. C-sqlite3-L/work/SQLite/sqlite_arm/lib-I/work/SQLite/sqlite_arm/include
Copy the database to the current folder. Test method:
./Test./test. DB "select * from test ;"