一、下载sqlite源码和dll库http://www.sqlite.org/download.html
二、在vs2012中新建工程,解压文件复制sqlite3.h,sqlite3.c文件到新建的项目中,配置将sqlite3.dll文件夹包含到项目中。
三、新建源文件,编写简单的测试。
#include <iostream>
#include <string>
#include<ctime>
#include <sqlite3.h>
using namespace std;
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
fprintf(stderr, "%s: ", (const char*)NotUsed);
for (i = 0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main()
{
char value[1000]={0};
sqlite3 *db;
char *zErrMsg = 0;
int rc;
int key=0;
const char *sql ;
string temp;
/* Open database */
rc = sqlite3_open("test.db", &db);
if (rc){
cout << "Can't open database test.db" << endl;
sqlite3_free(zErrMsg);
exit(0);
}
else{
cout << "open the database successful!" << endl;
}
// Create table statement
sql = "CREATE TABLE table1(key INT PRIMARY KEY NOT NULL,value TEXT NOT NULL);";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if (rc != SQLITE_OK){
cout << zErrMsg << endl;
sqlite3_free(zErrMsg);
}
else{
cout << "create table successful!" << endl;
}