當前位置:首頁 » 操作系統 » sqlite資料庫linux

sqlite資料庫linux

發布時間: 2023-08-04 20:14:39

❶ 請問在linux系統中QT連接sqlite資料庫怎麼連接呢查了很多資料,我是初學者,請問高手能詳細點指點嗎

Ruby 1.8.2
Rails 1.0.0
SQLite 3.3.3
下載 sqlite-3_3_3.zip sqlitedll-3_3_3.zip
解壓它們,得到文件sqlite3.exe和sqlite3.dll;
復制它們到目錄[RUBY_HOME]/bin下面;
SQLite-Ruby 1.1.0
如下命令安裝該模塊是針對SQLite 3.x版本:
gem install sqlite3-ruby -r -y
SQLite 3.x的可視化工具:SQLite Database Browser
解壓它,我們得到軟體SQLite Database Browser 1.2.1.exe

❷ 怎樣在Linux下從源代碼安裝SQLite3

安裝 SQLite3

Uncompress the tar.gz file and install SQLite3 as shown below.

解壓tar.gz文件並像下面所示安裝

tar xvfz sqlite-autoconf-3070603.tar.gz
cd sqlite-autoconf-3070603
./configure
make
make install

make安裝命令後會有以下的輸出。

test -z "/usr/local/bin" || mkdir -p -- "/usr/local/bin"
./libtool --mode=install /usr/bin/install -c sqlite3 /usr/local/bin/sqlite3
/usr/bin/install -c .libs/sqlite3 /usr/local/bin/sqlite3
test -z "/usr/local/include" || mkdir -p -- "/usr/local/include"
/usr/bin/install -c -m 644 'sqlite3.h' '/usr/local/include/sqlite3.h'
/usr/bin/install -c -m 644 'sqlite3ext.h' '/usr/local/include/sqlite3ext.h'
test -z "/usr/local/share/man/man1" || mkdir -p -- "/usr/local/share/man/man1"
/usr/bin/install -c -m 644 './sqlite3.1' '/usr/local/share/man/man1/sqlite3.1'
test -z "/usr/local/lib/pkgconfig" || mkdir -p -- "/usr/local/lib/pkgconfig"
/usr/bin/install -c -m 644 'sqlite3.pc' '/usr/local/lib/pkgconfig/sqlite3.pc'

提示:如果你對mysql資料庫有興趣,你也可以安裝在你的系統中。

❸ 如何在Linux中向sqlite3資料庫中插入數據

0. 引言 我們這篇文章主要講述了如何在C/C++語言中調用 sqlite 的函數介面來實現對資料庫的管理, 包括創建資料庫、創建表格、插入數據、查詢數據、刪除數據等。 1. 說明 這里我們假設你已經編譯好了sqlite的庫文件 : libsqlite3.a libsqlite3.la libsqlite3.so libsqlite3.so.0 libsqlite3.so.0.8.6 pkgconfig 和可執行文件 : sqlite3 我們再假設你的sqlite3的安裝目錄在 /usr/local/sqlite3 目錄下。 如果不是,我們可以這樣做,將你的安裝文件復制到 /usr/local/sqlite3 這個目錄, 這樣我們好在下面的操作中更加統一,從而減少出錯的概率 例如:[root@localhost home]# cp -rf sqlite-3.3.8-ix86/ /usr/local/sqlite3 這里假設 /home/sqlite-3.3.8-ix86/ 是你的安裝目錄,也就是說你的sqlite原來就是安裝在這里 這樣之後,我們的sqlite3的庫文件目錄是:/usr/local/sqlite3/lib 可執行文件 sqlite3 的目錄是: /usr/local/sqlite3/bin 頭文件 sqlite3.h 的目錄是: /usr/local/sqlite3/include 好拉,現在開始我們的Linux下sqlite3編程之旅。 2. 開始 這里我們現在進行一個測試。 現在我們來寫個C/C++程序,調用 sqlite 的 API 介面函數。 下面是一個C程序的例子,顯示怎麼使用 sqlite 的 C/C++ 介面. 資料庫的名字由第一個參數取得且第二個參數或更多的參數是 SQL 執行語句. 這個函數調用sqlite3_open() 在 16 行打開資料庫,並且sqlite3_close() 在 25 行關閉資料庫連接。 [root@localhost temp]# vi opendbsqlite.c 按下i 鍵切換到輸入模式,輸入下列代碼:// name: opendbsqlite.c // This prog is used to test C/C++ API for sqlite3.It is very simple,ha! // Author : zieckey All rights reserved. // data : 2006/11/13 #include <stdio.h> #include <sqlite3.h> int main( void ) { sqlite3 *db=NULL; char *zErrMsg = 0; int rc; //打開指定的資料庫文件,如果不存在將創建一個同名的資料庫文件 rc = sqlite3_open("zieckey.db", &db); if( rc ) { fprintf(stderr, "Can't open database: %s ", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } else printf("You have opened a sqlite3 database named zieckey.db successfully! Congratulations! Have fun ! ^-^ "); sqlite3_close(db); //關閉資料庫 return 0; } 退出,保存。(代碼輸入完成後,按下 Esc 鍵,然後輸入: :wq ,回車就好拉) 好拉,現在編譯:[root@localhost temp]# gcc opendbsqlite.c -o db.out 或者遇到這樣的問題:[root@localhost temp]# gcc opendbsqlite.c -o db.out opendbsqlite.c:11:21: sqlite3.h: 沒有那個文件或目錄 opendbsqlite.c: In function `main': opendbsqlite.c:19: `sqlite3' undeclared (first use in this function) opendbsqlite.c:19: (Each undeclared identifier is reported only once opendbsqlite.c:19: for each function it appears in.) opendbsqlite.c:19: `db' undeclared (first use in this function) 這是由於沒有找到頭文件的原因。 也許會碰到類似這樣的問題:[root@localhost temp]# gcc opendbsqlite.c -o db.out /tmp/ccTkItnN.o(.text+0x2b): In function `main': : undefined reference to `sqlite3_open' /tmp/ccTkItnN.o(.text+0x45): In function `main': : undefined reference to `sqlite3_errmsg' /tmp/ccTkItnN.o(.text+0x67): In function `main': : undefined reference to `sqlite3_close' /tmp/ccTkItnN.o(.text+0x8f): In function `main': : undefined reference to `sqlite3_close' collect2: ld returned 1 exit status 這是個沒有找到庫文件的問題。 下面我們著手解決這些問題。 由於用到了用戶自己的庫文件,所用應該指明所用到的庫,我們可以這樣編譯: [root@localhost temp]# gcc opendbsqlite.c -o db.out -lsqlite3 我用用 -lsqlite3 選項就可以了(前面我們生成的庫文件是 libsqlite3.so.0.8.6 等, 去掉前面的lib和後面的版本標志,就剩下 sqlite3 了所以是 -lsqlite3 )。 如果我們在編譯安裝的時候,選擇了安裝路徑,例如這樣的話:....... # ../sqlite/configure --prefix=/usr/local/sqlite3 # make .......作者:zieckey
insert into thetable values (...)

❹ Qt5 linux 無法連接sqlite

先安裝好sqlite,然後去系統軟體源中找qt自帶的sqlite的驅動安裝。
Linux平台下解決Qt5連接mysql資料庫的問題:輸入sudoapt-getinstalllibqt5sql5-mysql解決,這種方法只能解決Qt是用sudoapt-getinstallqt-sdk命令裝的低版本的Qt5(如5、2、x)缺少MySQL驅動問題,如果你的Qt5版本為5、7、X,那麼就不能用這種方法解決,請參考下面的方法。

❺ 在Linux環境里怎麼打開一個sqlite的資料庫

下載一個Linux 的sqlite3工具(或到SqLite網站下載sqlite的源代碼,在你的系統中編譯出sqlite3工具),用這個工具打開:
sqlite3 /tmp/test.db

❻ 如何在Linux下用C/C++語言操作資料庫sqlite3

1.SQLite資料庫特點(1)SQLite資料庫是開源的嵌入式資料庫,無需獨立的資料庫引擎,直接嵌入到應用程序進程中,因此,通過API,應用程序可以直接操作它。(2)事務的處理是原子的,一致的,獨立的,可持久化的(ACID),即使在系統崩潰和掉電後。(3)SQLite資料庫通過獨占性與共享鎖來實現事務的獨立處理。(4)一個單獨的跨平台的磁碟文件就能夠存儲一個資料庫。(5)能支持2TB級的數據。(6)自包含,無外部依賴性。(7)支持NULL,INTEGER,NUMERIC,REAL,TEXT和BLOG等數據類型。(8)SQLite資料庫沒有用戶帳戶的概念。資料庫的許可權僅依賴於文件系統。2.SQLite資料庫的基本操作(1)建立資料庫sqlite3data.sqlite3在當前目錄下建立了名為data.sqlite3的資料庫。(2)建立數據表createtablecall_list(idINTEGERPRIMARYKEY,typeNUMERIC,telnumNUMERIC,bttimeTEXT,tcountNUMERIC,charge_rateNUMERIC,charge_sumNUMERIC);建立了名為call_list的數據表,有7個欄位,分別為id,type,telnum,bttime,tcount,charge_sum.charge_rate.(3)向數據表中插入數據insertintocall_listvalues($num,1,2,'new',4,5,6);(4)查詢數據表中的數據select*fromcall_list;(5)修改call_list表中的數據updatecall_listsetid=00001000whereid=10001;(6)刪除表中的數據記錄deletefromcall_listwhereid=1000;(7)SQlite中的其它常用命令.tables-列出所有的資料庫中的數據表.schematablename-列出指定數據表的結構.quit-離開資料庫(8)SQLite資料庫的導入與導出a.將data.sqlite資料庫的數據全部導出:sqlite3data.sqlite>.outputdd.sql>.mp這樣,數據就保存在dd.sql的文件中,注意這個文件不是資料庫,而是SQL語句。然後再把這些數據導入到另外一個資料庫data1.sqlite資料庫中。sqlite3data1.sqlite>.readdd.sql這樣,數據就從data.sqlite資料庫復制到data1.sqlite資料庫中去了。b.將數據表中的數據導出到a.txt中去.outputa.txt//輸出重定向到a.txtselect*fromcall_list;c.將導出的表中的數據導入到另一個資料庫的新建的表中去如:當從data.sqlite中的call_list表中導出了數據,再導入到另外一個資料庫表call中去。首先建立表call.然後.importa.txtcall即可。3.C語言操作Sqlite資料庫API:intsqlite3_open(constchar*filename,sqlite3**ppdb);第一個參數用來指定資料庫文件名。第二個參數是一個資料庫標識符指針。如果打開資料庫成功,則返回0,否則返回一個錯誤代碼。intsqlite3_close(sqlite3*);傳遞的參數是資料庫標識符指針用來關閉資料庫,操作成功是返回0,否則返回一個錯誤代碼。intsqlite3_errcode(sqlite3*db);constchar*sqlite3_errmsg(sqlite3*db);constchar*sqlite3_errmsg16(sqlite3*db);這三個函數都是返回錯誤信息,第一個函數返回的是最近調用資料庫介面的錯誤代碼,第二,第三個函數是返回最近調用資料庫介面的錯誤信息。第二個函數返回的錯誤信息是用UTF-8編碼的,第三個函數返回的錯誤信息是用UTF-16編碼的。intsqlite3_exec(sqlite3*,constchar*sql,int(*callback)(void*,int,char**,char**),void*,**errmsg);這個函數非常重用,是用來執行SQLite資料庫的SQL語句的。第一個參數是sqlite資料庫標識符指針。第二個參數是要執行的SQL語句。第三個參數是一個回調函數,在執行查詢操作時用到,其它的操作可以傳空值即NULL。第四個參數是傳遞給回調函數第一個參數的實參。第五個參數是一個錯誤信息。回調函數:intcallback(void*,intargc,char**argv,char**cname);第一個參數是從sqlite3_exec傳遞過來的參數,可以為任意的類型。第二個參數是查詢的列數。第三個參數是查詢結果集的值。第四個參數是列名。intsqlite3_get_table(sqlite3*db,constchar*sql,char***result,int*row,int*col,char**errmsg);這個函數主要是用來查詢的。第一個參數是資料庫描述符指針第二個參數是SQL語句。第三個參數是查詢的結果集。第四個參數是結果集中的行數。第五個參數是結果集中的列數。第六個參數是錯誤信息。它查詢出的行數是從欄位名開始的。即第0行是欄位名。實例:/**本例主要實現用Sqlite的回調函數進行查詢intsqlite3_exec(sqlite3*,constchar*sql,int(*callback)(void*,int,char**,char**),void*,errmsg);第一個參數是資料庫標識符第二個參數是要執行的sql命令第三個參數是回調函數第四個參數是回調函數的第一個參數第五個參數是用於指示錯誤信息其中回調函數的形式:int_sql_callback(void*arg,intargc,char**argv,char**cname);第二個參數指示結果集中的列數第三個參數是保存結果集的字元串第四個參數是結果集中的列名**/#include#include#include#include#include#includeint_call_back(void*arg,intargc,char**argv,char**cname);intmain(){intres;constchar*dbfile="data.sqlite1";char*errmsg=NULL;sqlite3*db;res=sqlite3_open(dbfile,&db);if(res!=0){perror("資料庫打開失敗");exit(EXIT_FAILURE);}//創建一張數據表constchar*sqlcreate="createtablecall_list(idINTEGERPRIMARYKEY,typeNUMERIC,telnumNUMERIC,bttimeTEXT,tcountNUMERIC,charge_rateNUMERIC,charge_sumNUMERIC)";res=sqlite3_exec(db,sqlcreate,NULL,NULL,&errmsg);if(res!=0){perror("建立數據表失敗");exit(EXIT_FAILURE);}//插入100000條數據intnum=0;structtimevaltv;gettimeofday(&tv,NULL);longold=tv.tv_sec;while(num<100000){constchar*sqlinsert="insertintocall_listvalues($num,1,2,'new',4,5,6)";res=sqlite3_exec(db,sqlinsert,NULL,NULL,&errmsg);//插入時不需要用到回調函數if(res!=0){perror("插入失敗");exit(EXIT_FAILURE);}num++;}gettimeofday(&tv,NULL);printf("插入100000條數據的時間為:%d秒/n",(tv.tv_sec-old));//更新constchar*sqlupdate="updatecall_listsetid=00001000whereid=10001";res=sqlite3_exec(db,sqlupdate,NULL,NULL,&errmsg);if(res!=0){perror("更新數據失敗");exit(EXIT_FAILURE);}//刪除constchar*sqldelete="deletefromcall_listwhereid=1000";res=sqlite3_exec(db,sqldelete,NULL,NULL,&errmsg);if(res!=0){perror("刪除數據失敗");exit(EXIT_FAILURE);}//查詢constchar*sqlquery="select*fromcall_list";res=sqlite3_exec(db,sqlquery,&_call_back,NULL,&errmsg);if(res!=0){printf("%s/n",errmsg);perror("執行失敗/n");exit(EXIT_FAILURE);}res=sqlite3_close(db);if(res!=0){perror("資料庫關閉失敗");exit(EXIT_FAILURE);}exit(EXIT_SUCCESS);}int_call_back(void*arg,intargc,char**argv,char**cname){inti;//二重指針可以看成指針數組for(i=0;i

❼ 如何在Linux下用C語言操作資料庫sqlite3

下面我們看看怎麼在C語言中向資料庫插入數據。
好的,我們現編輯一段c代碼,取名為 insert.c
// name: insert.c
// This prog is used to test C/C++ API for sqlite3 .It is very simple,ha !
// Author : zieckey All rights reserved.
// data : 2006/11/18
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"
#define _DEBUG_
int main( void )
{
sqlite3 *db=NULL;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("zieckey.db", &db); //打開指定的資料庫文件,如果不存在將創建一個同名的資料庫文件
if( rc )
{
fprintf(stderr, "Can't open database: %s
", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
else printf("You have opened a sqlite3 database named zieckey.db successfully!
Congratulations! Have fun ! ^-^
");
//創建一個表,如果該表存在,則不創建,並給出提示信息,存儲在 zErrMsg 中
char *sql = " CREATE TABLE SensorData(
ID INTEGER PRIMARY KEY,
SensorID INTEGER,
SiteNum INTEGER,
Time VARCHAR(12),
SensorParameter REAL
);" ;
sqlite3_exec( db , sql , 0 , 0 , &zErrMsg );
#ifdef _DEBUG_
printf("%s
",zErrMsg);
#endif
//插入數據
sql = "INSERT INTO "SensorData" VALUES( NULL , 1 , 1 , '200605011206', 18.9 );" ;
sqlite3_exec( db , sql , 0 , 0 , &zErrMsg );
sql = "INSERT INTO "SensorData" VALUES( NULL , 1 , 1 , '200605011306', 16.4 );" ;
sqlite3_exec( db , sql , 0 , 0 , &zErrMsg );
sqlite3_close(db); //關閉資料庫
return 0;
}

好的,將上述代碼寫入一個文件,並將其命名為 insert.c 。
解釋:
sqlite3_exec的函數原型說明如下:
int sqlite3_exec(
sqlite3*,
const char *sql,
sqlite_callback,
void *,
char **errms

g
);

編譯:
[root@localhost temp]# gcc insert.c -lsqlite3 -L/usr/local/sqlite3/lib -I/usr/local/sqlite3/include
insert.c:28:21: warning: multi-line string literals are deprecated
[root@localhost temp]#
執行
[root@localhost temp]# ./a.out
./a.out: error while loading shared libraries: libsqlite3.so.0: cannot open shared object file: No such file or directory
[root@localhost temp]#
同樣的情況,如上文處理方法:
[root@localhost temp]# export LD_LIBRARY_PATH=/usr/local/sqlite3/lib:$LD_LIBRARY_PATH
[root@localhost temp]# ./a.out
You have opened a sqlite3 database named zieckey.db successfully!
Congratulations! Have fun ! ^-^
(null)
(null)
(null)
[root@localhost temp]#
運行成功了,好了,現在我們來看看是否插入了數據
[root@localhost temp]# /usr/local/sqlite3/bin/sqlite3 zieckey.db
SQLite version 3.3.8
Enter ".help" for instructions
sqlite> select * from SensorData;
1|1|1|200605011206|18.9

2|1|1|200605011306|16.4
sqlite>

❽ linux sqlite3用資料庫命令怎麼創建資料庫

方法/步驟 首先下載 Navicat for SQLite,下載後解壓縮。 運行navicat.exe 這個主程序,在左上角點擊連接 在彈出窗口中輸入連接名,選擇類型,然後在下面選擇資料庫文件,或者資料庫保存位置。 這樣就在指定位置創建了一個Sqlite資料庫文件了

熱點內容
如何登錄微信找回密碼 發布:2025-03-13 05:06:20 瀏覽:448
pc游戲編程人機博弈源碼 發布:2025-03-13 04:51:45 瀏覽:604
手機原生配置低怎麼玩流暢 發布:2025-03-13 04:35:31 瀏覽:735
分線器安卓供電口有什麼用 發布:2025-03-13 04:19:54 瀏覽:136
埠訪問關系 發布:2025-03-13 03:49:50 瀏覽:789
運用零基預演算法 發布:2025-03-13 03:45:30 瀏覽:791
安卓伺服器搭建web 發布:2025-03-13 03:40:26 瀏覽:317
銅板演算法 發布:2025-03-13 03:40:25 瀏覽:621
ins怎麼保存圖片安卓 發布:2025-03-13 03:38:14 瀏覽:214
什麼資料庫快 發布:2025-03-13 03:34:38 瀏覽:52