在c++中使用SQlite

來源:互聯網
上載者:User

1. 產生 .lib 檔案

  從http://www.sqlite.org下載SQLite3.dll和SQLite3.def檔案,以vc++6.0為例:

第一步:找到lib.exe所在目錄

一般都在X:\Program Files\Microsoft Visual Studio\VC98\Bin下,在“運行”中輸入cmd,然後切換到該目錄下

第二步:使用LIB命令產生.lib檔案

很多網頁上都介紹,使用LIB /DEF:sqlite3.def /machine:IX86即可產生,可是我使用它時遇到一些小問題。

這裡就不說了,說說應該注意的幾點問題吧。第一個,你的sqlite3.def要是沒有在 X:\Program Files\Microsoft Visual Studio\VC98\Bin下,需要寫全路徑;第二,為了清楚起見,你需要註明.lib檔案的輸出路徑。下面我給出一個完整的命令列:X:\Program Files\Microsoft Visual Studio\VC98\Bin>LIB /out:D:\test\sqlite3.lib /MACHINE:IX86 /DEF:D:\test\sqlite3.def,然後在X:\test\e中可以找到sqlite3.lib和sqlite3.exp

如果產生的過程中提示缺少檔案,去vc安裝目錄搜尋,複製到lib.exe檔案下就行了。

2.在C++中 使用sqlite

#include <iostream>#include <string>using namespace std;#include "sqlite/sqlite3.h"#pragma comment(lib,"sqlite/sqlite3.lib")int main(){    sqlite3* db;    int nResult = sqlite3_open("test.db",&db);    if (nResult != SQLITE_OK)    {        cout<<"開啟資料庫失敗:"<<sqlite3_errmsg(db)<<endl;        return 0;    }    else    {        cout<<"資料庫開啟成功"<<endl;    }    char* errmsg;    nResult = sqlite3_exec(db,"create table fuck(id integer primary key autoincrement,name varchar(100))",NULL,NULL,&errmsg);    if (nResult != SQLITE_OK)    {         sqlite3_close(db);         cout<<"建立表失敗:"<<sqlite3_errmsg(db)<<endl;        return 0;    }    string strSql;    for (int i=0;i<100;i++)    {        strSql+="insert into fuck values(null,'heh');";    }    cout<<strSql<<endl;    nResult = sqlite3_exec(db,strSql.c_str(),NULL,NULL,&errmsg);    if (nResult != SQLITE_OK)    {        sqlite3_close(db);        cout<<"插入資料失敗:"<<sqlite3_errmsg(db)<<endl;        return 0;    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.