1.Generate a. Lib File
Download the sqlite3.dll and sqlite3.def files from the http://www.sqlite.org. Take VC ++ 6.0 as an example:
Step 1: Find the directory of lib.exe
Generally, under X: \ Program Files \ Microsoft Visual Studio \ vc98 \ bin, Enter cmd in "run" and switch to the directory
Step 2: Use the Lib command to generate the. Lib File
As described on many web pages, lib/DEF: sqlite3.def/machine: ix86 can be used for generation, but I encountered some minor problems when using it.
I will not talk about it here. Let's talk about some points that should be paid attention. First, if your sqlite3.def is not in X: \ Program Files \ Microsoft Visual Studio \ vc98 \ bin, you need to write the full path. Second, you need to specify it for clarity. lib file output path. The following is a complete command line: X: \ Program Files \ Microsoft Visual Studio \ vc98 \ bin> lib/out: D: \ test \ sqlite3.lib/machine: ix86/DEF: d: \ test \ sqlite3.def, and then sqlite3.lib and sqlite3.exp can be found in X: \ test \ e.
If there are few files missing during the process, go to the vcss installation directory to search for the files and copy them to the lib.exe file.
2. Use SQLite in C ++
# Include <iostream> # Include < String > Using Namespace STD; # include " SQLite/sqlite3.h " # Pragma Comment (Lib, "SQLite/sqlite3.lib ") Int Main () {sqlite3 * DB; Int Nresult = sqlite3_open ( " Test. DB " ,& DB ); If (Nresult! = Sqlite_ OK) {cout < " Failed to open database: " <Sqlite3_errmsg (db) < Endl; Return 0 ;} Else {Cout <" Database opened successfully " < Endl ;} Char * Errmsg; nresult = Sqlite3_exec (dB, " Create Table fuck (ID integer primary key autoincrement, name varchar (100 )) " , Null, null ,& Errmsg ); If (Nresult! = Sqlite_ OK) {sqlite3_close (db); cout <" Failed to create table: " <Sqlite3_errmsg (db) < Endl; Return 0 ;} String Strsql; For ( Int I = 0 ; I < 100 ; I ++ ) {Strsql + = " Insert into fuck values (null, 'heh '); " ;} Cout <Strsql < Endl; nresult = Sqlite3_exec (dB, strsql. c_str (), null, null ,& Errmsg ); If (Nresult! = Sqlite_ OK) {sqlite3_close (db); cout < " Failed to insert data: " <Sqlite3_errmsg (db) < Endl; Return 0 ;} Return 0 ;}