再次,Project->Properties->C/C++->Precompiled Header->Create/Use Precompiled Header: Not using precompiled Header
再次,Project->Properties->Linker->Input-> Module Definition File: 输入“sqlite3.def”
再次,有可能会出现unresolved external symbol @__security_check_cookie@4这个链接错误,做如下操作即可:Project->Properties->C/C++->Code Generation, Buffer Security Check选择No
上述过程完成后即可得到一个sqlite3.lib和sqlite3.dll
4. 如果想使用c++封装,可以到下面下载:http://softvoile.com/development/CppSQLite3U/
下面的代码是测试(代码是转载的)
4> 有了 SQLite DLL 及 CppSQLite3U 后,便可以很方便地使用 SQLITE :(步骤3中,a链接页画下就有DEMO)
主要代码如下:
- #define FILE_DB_NAME TEXT("unitech.db")
-
-
- void GetCurrentDirectory(CString &szPath)
- {
- wchar_t pBuf[256];
- GetModuleFileName(NULL,pBuf,sizeof(pBuf)/sizeof(wchar_t));
- szPath=pBuf;
- szPath = szPath.Left(szPath.ReverseFind('\\')+1);
- }
-
- void CDemo2Dlg::OnButton1()
- {
- CString strDbPath;
- GetCurrentDirectory(strDbPath);
- strDbPath += FILE_DB_NAME;
-
- CppSQLite3DB db;
- try
- {
-
- db.open(strDbPath);
-
-
- if(db.tableExists(L"tblTest"))
- {
- AfxMessageBox(L"Table: tblTest is existed!");
- }
- else
- {
- AfxMessageBox(L"Table: tblTest not existed!");
-
- db.execDML(L"create table tblTest
- (empno varchar(20), empname varchar(20))");
- }
-
-
- db.execDML(L"insert into tblTest values(' 编号', '姓名')");
-
- db.execDML(L"insert into tblTest values(' 精瑞电脑', 'Answer')");
-
-
- db.execDML(L"delete from tblTest where empno=' 编号'");
-
-
- TCHAR buf[256];
- db.execDML(L"begin transaction;");
- for (int i = 0; i < 10; i++)
- {
- memset(buf, 0, sizeof(buf));
- wsprintf(buf, L"insert into tblTest
- values ('no%d', 'name%d');", i, i);
- db.execDML(buf);
- }
- db.execDML(L"commit transaction;");
-
-
- db.execDML(L"update tblTest set empname='answer' where empno='no1'");
-
-
- int count = db.execScalar(L"select count(*) from tblTest;");
- TCHAR szCount[50];
- memset(szCount, 0, sizeof(szCount));
- wsprintf(szCount, L"Count:%d", count);
- AfxMessageBox(szCount);
-
-
- CppSQLite3Query q = db.execQuery(L"select * from tblTest");
- while (!q.eof())
- {
- AfxMessageBox(q.fieldValue(0));
- q.nextRow();
- }
- q.finalize();
-
- db.close();
- AfxMessageBox(L"OK");
- }
- catch(CppSQLite3Exception ex)
- {
- AfxMessageBox(ex.errorMessage());
- }
- }
|