代码语言:javascript复制
//插入数据
#include "CppSQLite3.h"
#include <io.h>
CppSQLite3DB db;
BOOL re = _access("config.db", 0);//判文件是否存在
if (re != -1)//等于-1表示不存在
{
db.open("config.db");
CppSQLite3Buffer bufSQL;
bufSQL.format("insert into UserManage(UserName) values (%Q)", W2A(strName));
TRACE(_T("%s"), CString((const char*)bufSQL));
db.execDML(bufSQL);
}
else
{
AfxMessageBox(_T("文件不存在!"));
}
代码语言:javascript复制//查询
CppSQLite3DB db;
db.open("C:\config.db");
CppSQLite3Query q = db.execQuery("select * from userManage");
for (int fld = 0; fld < q.numFields(); fld )
{
TRACE(_T("%sn"), CString( q.fieldName(fld)));
}
while (!q.eof())
{
TRACE(_T("%s,%s,%sn"),CString(q.fieldValue(0)),
CString(q.fieldValue(1)),
CString(q.fieldValue(2)));
q.nextRow();
}
创建表时,请用SQLite Developer工具,将编码格式设置为ANSI类型,否则读取时会出现乱码。