Download the source code of sqlite. The sqlite3.c source code and sqlite3.h are header files.
You can compile sqlite as a static library and then use it in other projects. The advantage of this is that you do not need to mix the test program with sqlite source, resulting in slow compilation and inconvenient use.
Sqlite Compilation
1. Create a win32 Project in vc ++, set Applicationtype to Static libray in The Wizard tool, set Additional options to null, and set add common header file to null.
2. After the project is created, add the sqlite3.c source code in source, and add sqlite. h.
3. compile the project. At this time, the static library sqlite3.lib file for other projects has been generated. If you need to use the sqlite database later, you only need to introduce the sqlite3.h header file and sqlite3.lib.
Sqlite sample program
1. Create a win32 Project sqlitesample in vc ++, and select the Console program in the Wizard.
Introduce the sqlite. h header file.
2. The source code in main is as follows:
Sqlite learning-compile the sqlite static library for other projects to call) download the sqlite source code, in which sqlite3.c source code, sqlite3.h is the header file. You can compile sqlite as a static library and then use it in other projects. The advantage of this is that you do not need to mix the test program with sqlite source, resulting in slow compilation and inconvenient use. Sqlite compilation 1 creates a win32 Project in vc ++. In the wizard tool, set Applicationtype to Static libray, set Additional options to null, and set add common header file to null. 2. After the project is created, add the sqlite3.c source code to source and add the sqlite. h.3 compilation project to header files. The static library sqlite3.lib file for other projects has been generated. If you need to use the sqlite database later, you only need to introduce the sqlite3.h header file and sqlite3.lib. Create a win32 Project sqlitesample in vc ++ and select the Console program in the Wizard. Introduce the sqlite. h header file. 2. The source code in main is as follows # include "stdafx. h "# include ".. /sqlitelib/sqlite3.h "# include" string. h "# pragma comment (lib ,".. /Debug/sqlitelib. lib ") void doTest (); int _ tmain (int argc, _ TCHAR * argv []) {doTest (); return 0;} void doTest () {sqlite3 * conn = NULL; const char * createTableSQL = "create table testtable (int_col INT, float_col REAL, string_col TEXT )"; const char * selectSQL = "SELECT * from testtable where 1 = 0 "; sqlite3_stmt * stmt = NULL; int len = strlen (createTableSQL); int result = sqlite3_open (" E: \ Hbb0b0 \ sqlitedb \ mytest. db ", & conn); sqlite3_stmt * stmt2 = NULL; // 1. open the database if (result! = SQLITE_ OK) {sqlite3_close (conn); return;} // 2. Prepare to create a data table. If creation fails, use sqlite3_finalize to release the sqlite3_stmt object to prevent memory leakage. If (sqlite3_prepare_v2 (conn, createTableSQL, len, & stmt, NULL )! = SQLITE_ OK) {if (stmt) sqlite3_finalize (stmt); sqlite3_close (conn); return ;}// 3. Run the sqlite3_step command to create a table. For DDL and DML statements, sqlite3_step executes the correct return value // only SQLITE_DONE. For SELECT queries, if any data returns SQLITE_ROW, it returns // SQLITE_DONE when it reaches the end of The result set. If (sqlite3_step (stmt )! = SQLITE_DONE) {sqlite3_finalize (stmt); sqlite3_close (conn); return ;}// 4. release resources for creating TABLE statement objects. Sqlite3_finalize (stmt); printf ("Succeed to create test table now. \ n"); // 5. Construct the sqlite3_stmt object for querying table data. If (sqlite3_prepare_v2 (conn, selectSQL, strlen (selectSQL), & stmt2, NULL )! = SQLITE_ OK) {if (stmt2) sqlite3_finalize (stmt2); sqlite3_close (conn); return ;}3 after compilation and running, you can install firefox sqlite manager to view the final generation of mytest. db. the corresponding table is successfully generated.
3. After compilation and running, you can install firefox sqlite manager to view the final mytest. db generated.
The corresponding table is successfully generated.