1. Download sqlite
SQLite can go to the official site to download http://www.sqlite.org/download.html
Use sqlite in VC
To download sqlitedll-3_7_2.zipand sqlite-amalgamation-3_7_2.zip
Ii. compilation process
After the dll package is decompressed, there is a sqlite3.dll and a sqlite3.def file. The lib file for VC ++ 6.0 is not provided. You can use the sqlite3.def file to generate the file as follows:
1. Copy sqlite3.h(in sqlite-amalgamation-3_7_2.zip) to C: \ Program
Files \ Microsoft Visual Studio \ VC98 \ Include directory;
2. start a command line Program and go to the installation directory C: \ Program Files \ Microsoft Visual Studio \ VC98 \ binof VC. A lib.exe file is available under this directory, and you can use it to generate the sqlite3.lib file, copy the sqlite3.def file to the same directory, and then enter the following command on the command line:
LIB/MACHINE: IX86/DEF: sqlite3.def
This command generates two files: sqlite3.lib and sqlite3.exp.
When running this command, if you are prompted that the MSPDB60.DLL file cannot be found, you can copy it from another directory to the Bin directory;
3. Copy the generated sqlite3.lib to the C: \ Program Files \ Microsoft Visual Studio \ VC98 \ Lib directory and copy sqlite3.dll to the C: \ WINDOWS \ system32 directory;
4. Write a win32 console application to call the sqlite API, including the header file of sqlite3.h, and add sqlite3.lib to the Project Link. Project-> Settings, Link tab, Object/library
Modules is added to sqlite3.lib, and the compilation link is passed.
5. Compile the sqlitesource code under vcss to generate sqlite3.exe,
When can not find tcl. h appears, remove tclsqlite. c or add # define NO_TCL before this file.
Remove tcl support. Create a directory named sqlite3 on the C drive, copy sqlite3.exe, and open a command line terminal to access this directory. Then, you can use the sqlite3 command in the terminal to create databases and tables, and use query and other commands.
3. Use sqlite3 API in VC/MFC
The source code of the Win32 console test program is as follows:
# Include "stdafx. h"
# Include <stdio. h>
# Include <stdlib. h>
# Include <sqlite3.h>
Int main (int argc, char * argv [])
{
Sqlite3 * db;
Int result;
Char * errmsg = NULL;
Char ** dbResult;
Int nRow, nColumn;
Int I, j;
Int index;
Result = sqlite3_open ("c :\\ sqlite3 \ test. db", & db );
If (result! = SQLITE_ OK)
{
Printf ("failed to open database! \ N ");
Return-1;
}
Result = sqlite3_get_table (db, "select * from student", & dbResult, & nRow, & nColumn, & errmsg );
If (SQLITE_ OK = result)
{
Index = nColumn;
Printf ("total % d records \ n", nRow );
For (I = 0; I <nRow; I ++)
{
For (j = 0; j <nColumn; j ++)
{
Printf ("segment name: % s segment value: % s \ n", dbResult [j], dbResult [index]);
++ Index;
}
Printf ("------- \ n ");
}
}
Sqlite3_free_table (dbResult );
Sqlite3_close (db );
Return 0;
}
The screenshot is as follows:
In addition, I wrote a dialog box-based MFC Test Program, a simple student achievement management system, and used the SQLite database in the VC environment. The screenshot is as follows: