下载sqlite3.h,sqlite3.lib,sqlite3.dll
可从https://download.youkuaiyun.com/download/weixin_40385285/86728084下载
需要进行gb2312和utf_8的替换
打开数据库
sqlite3* conn;
if (SQLITE_OK != sqlite3_open(GB2UTF8(temp1.c_str()), &conn))
{
cout<"无法打开sqlite数据库";
return false;
}
创建表
char *err_msg;//操作失败的原因。
string ssql="CREATE TABLE [表名]([列名] varchar(30) unique)";
if (SQLITE_OK != sqlite3_exec(conn, GB2UTF8(sql.c_str()),
0, 0, &err_msg))
{
string temp=GB2UTF8(err_msg);
message="创建sqlite表失败,失败原因为:"+temp;
return false;
}
获取查询内容
sqlite3_stmt* result;
const unsigned char * content;//接收数据库查询信息
string selects="select * from "+table[j];
if(SQLITE_OK!=sqlite3_prepare_v2(conn,GB2UTF8(sql.c_str()),-1,&result,0))
{
string temp=UTF82GB(err_msg);
message="导入.csv失败,失败原因为:"+temp;
return false;
}
while(sqlite3_step(result) == SQLITE_ROW)//如果有数据内容
{
content = sqlite3_column_text( result, 0 );
string a=string(reinterpret_cast<const char*>(UTF82GB((const char*)content)));
cout<<a<<endl;
}
关闭数据库
sqlite3_close(conn);