环境:
vs2015
1. 准备
将生成的sqlite3.lib放入到工程下
将.h头文件放入到工程目录下,并且在vs工程中添加头文件
2. 代码
//
#include <stdio.h>
#include "stdafx.h"
#include <cstring>
#include "sqlite3.h"
#pragma comment(lib,"sqlite3.lib")
int main()
{
sqlite3 *db;
int rc;
const char *sql;
sqlite3_stmt *stmt;
rc = sqlite3_open("test.db", &db);
sql = "INSERT INTO user (id,username) VALUES(?,?)";
rc = sqlite3_exec(db, "BEGIN TRANSACTION;", NULL, NULL, NULL);
/*
rc = sqlite3_prepare(db, sql, -1, &stmt, NULL);
sqlite3_bind_text(stmt, 1, "123", strlen("123"), SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, "yuanlin2", strlen("yuanlin2"), SQLITE_TRANSIENT);
*/
rc = sqlite3_exec(db, "INSERT INTO user (id,username) VALUES('123','hehe')", NULL, NULL, NULL);
rc = sqlite3_exec(db, "COMMIT TRANSACTION;", NULL, NULL, NULL);
return 0;
}