I. SQLiteSQLite is a lightweight database and an acid-compliant associated database management system. It is designed to be embedded and has been used in many embedded products, it occupies very low resources. In embedded devices, it may only need several hundred KB of memory. It supports mainstream operating systems such as Windows, Linux, and UNIX, and can be combined with many programming languages, as well as ODBC interfaces, similar to MySQL and PostgreSQL, the two world-renowned open-source database management systems, the processing speed is faster than that of them. SQLite is also used in many software applications. Open the installation directory of Apsara to see SQLite. It is estimated that SQLite is used to store chat records.
Ii. Download SQLiteMy next example is sqlite-amalgamation-3071400.zip, which contains the main source code. Sqlite-dll-win32-x86-3071400.zip this is the Windows compiled DLL file and Def file, after decompression contains two files, sqlite3.def and sqlite3.dll. The compilation source code is very simple. A new CIDR project is created. copy the files decompressed by sqlite-amalgamation-3071400.zip to compile and link the files. My goal is to use the SQLite database as a part of my project and embedded part. Use the sqlite3.dll file. However, the source files are only sqlite3.def and sqlite3.dll, and there are no sqlite3.lib files. How can this problem be solved? The corresponding lib file can be generated based on the def file. The following command line is used to generate the Lib file. Find the installation path of vs. My path is D: \ ProgramFiles \. Use the command line to enter the following path.
D:\Program Files\Microsoft Visual Studio 9.0\VC\bin>lib /def:sqlite3.def /machine:ix86
Iii. Use
1 // # pragma comment (Lib, "sqlite3.lib ") 2 # include <iostream> 3 # include <string> 4 # include <sstream> 5 # include "sqlite3.h" 6 7 using namespace STD; 8 9 sqlite3 * PDB; 10 static int callback (void * notused, int argc, char ** argv, char ** azcolname) 11 {12 INT I = 0; 13 STD :: cout <azcolname [I] <"=" <(argv [I]? Argv [I]: "null") <, "; 14 STD: cout <" \ n "; 15 return 0; 16} 17 int main () 18 {19 int res = sqlite3_open ("mydatabase. DB ", & PDB); 20 if (RES) {21 STD: cout <" can't open database: "<sqlite3_errmsg (PDB ); 22 sqlite3_close (PDB); 23 return-1; 24} 25 char * errmsg; 26 string droptab = "Drop table test ;"; 27 string createstrsql = "create table test (one int, two long);"; 28 int res; 29 res = sq1 _ E3_exec (PDB, droptab. c_str (), 0,0, & errmsg); 30 if (res! = Sqlite_ OK) 31 {32 STD: cout <"An error occurred while executing the SQL statement. "<errmsg <STD: Endl; 33 return-1; 34} 35 res = sqlite3_exec (PDB, createstrsql. c_str (), 0, 0, & errmsg); 36 IF (res! = Sqlite_ OK) 37 {38 STD: cout <"An error occurred while executing the SQL statement for table creation. "<errmsg <STD: Endl; 39 return-1; 40} 41 else 42 STD: cout <" the SQL statement for table creation is successfully executed. "<STD: Endl; 43 44 for (INT I = 1; I <10; ++ I) 45 {46 stringstream strsql; 47 strsql <"insert into test values ("; 48 strsql <I <"," <(I + 10) <");"; 49 STD :: string STR = strsql. STR (); 50 res = sqlite3_exec (PDB, str. c_str (), 0, 0, & errmsg); 51 if (res! = Sqlite_ OK) 52 {53 STD: cout <"An error occurred while executing the SQL statement. "<errmsg <STD: Endl; 54 return-1; 55} 56} 57 string strsql =" select * from test; "; 58 int res = sqlite3_exec (PDB, strsql. c_str (), callback, 0, & errmsg); 59 If (res! = Sqlite_ OK) 60 {61 STD: cout <"An error occurred while executing the SQL statement. "<errmsg <STD: Endl; 62 Return-1; 63} 64 else 65 STD: cout <" the SQL statement is successfully executed. "<STD: Endl; 66 return 0; 67}