I've got it!
Download from http://www.sqlite.org/download.html first file : sqlite-amalgamation-3071100.zip(1.30 MiB) .This ZIP archive contains all C source code for SQLite 3.7.11 combined into a single source file. Unzip it to the your project directory (where your .cpp and .h files are). Then, in Visual Studio 2010 create project MFC application and add into your .cpp file :
#include sqlite3.h
. In Solution Explorer in Header Files add sqlite3.h file . And in Source Files add sqlite3.c file. In Source Files by right clicking choose Property of sqlite3.c file and there in C/C++ section in /Precompiled Headers at right side in Precompiled Header choose Not Using Precompiled Headers.
In menu of Visual Studio click Project and at the bottom click on Properties, and in opened window in Configuration choose All Configurations. In General --> Use of MFC should be as Shared DLL , then Use of ATL as Not Using ATL, Common Language Runtime as No CLR.
At C/C++ --> Code Generation --> Runtime Library should be set Multi-Threaded DLL (/MD).
Add this code at the end of your .cpp file and debug your project:
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
int i;
for(i=0; i<argc;> {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int _tmain(int argc, char* argv[])
{
sqlite3 *db; char *zErrMsg = 0;
int rc;
rc = sqlite3_open("test.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
}
else
{
fprintf(stderr, "Open database successfully\n\n");
}
const char *pSQL[6];
pSQL[0] = "create table myTable (FirstName varchar(30), LastName varchar(30), Age smallint)";
pSQL[1] = "insert into myTable (FirstName, LastName, Age) values ('Woody', 'Alan', 45)";
pSQL[2] = "insert into myTable (FirstName, LastName, Age) values ('Micheal', 'Bay', 38)";
pSQL[3] = "select * from myTable";
pSQL[4] = "delete from myTable";
pSQL[5] = "drop table myTable";
for(int i = 0; i < 4; i++)
{
rc = sqlite3_exec(db, pSQL[i], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
break;
}
}
sqlite3_close(db);
getchar();
return 0;
}
And add test.bd file to your project.