SQLite是一個包含在C函式庫中的輕量級資料庫。它並不需要獨立的維護程序,並且允許使用非標準變體(nonstandard variant)的SQL查詢語句來存取資料庫。
一些應用可是使用SQLite保存內部資料。它也可以在建立應用原型的時候使用,以便以後轉移到更大型的資料庫。
SQLite的主要優點:
1. 一致性的文件格式:
在SQLite的官方文件中是這樣解釋的,我們不要將SQLite與Oracle或PostgreSQL去比較,與我們自訂格式的資料檔相比,SQLite不僅提供了很好的
移植性,如大端小端、32/64位元等平台相關問題,而且還提供了資料存取的高效性,如基於某些資訊建立索引,從而提高訪問或排序該類別資料的效能,SQLite提供的事務功能,也是在操作普通文件時無法有效保證的。
2. 在嵌入式或行動裝置上的應用:
由於SQLite在運行時佔用的資源較少,而且無需任何管理開銷,因此對於PDA、智慧型手機等
行動裝置來說,SQLite的優勢毋庸置疑。
3. 內部資料庫:
在有些應用場景中,我們需要為插入到資料庫伺服器中的資料進行資料過濾或資料清理,以確保最終插入資料庫伺服器中的資料有效性。有的時候,數據是否有效,不能透過單一記錄來進行判斷,而是需要和之前一小段時間的歷史數據進行特殊的計算,再透過計算的結果判斷當前的數據是否合法。
在這種應用中,我們可以用SQLite緩衝這部分歷史資料。還有一種簡單的場景也適用於SQLite,即統計資料的預計算。例如我們正在運行數據即時採集的服務程序,我們可能需要將每10秒的數據匯總後,形成每小時的統計數據,該統計數據可以極大的減少用戶查詢時的數據量,從而大幅提高前端程序的查詢效率。在這種應用中,我們可以將1小時內的採集資料均快取在SQLite中,在達到整點時,計算快取資料後清空該資料。
4. 資料分析:
可以充分利用SQLite提供SQL特徵,完成簡單的資料統計分析的功能。這一點是yaml,csv檔案無法比擬的。
用我的話來說,他很小,很適合做臨時的資料庫,遷移資料很簡單,直接傳遞檔案就可以了。 其實我一開是選用leveldb的,但是他的特性像nosql,一些稍微複雜的查詢,就有些麻煩了。
1、建立一個新的資料庫:sqlite3 檔名
這個test.db 存放著所有的資料。
sqlite3 rui.db
2、打開一個已經存在的資料庫:sqlite3 已經存在的檔案名稱
存在,則新建;如果存在,則開啟。
3、匯入資料:.read 資料檔案
開啟記事本,並將下列SQL 語句複製到記事本中,儲存為test.sql 到上面說到的Db 目錄下,在命令列環境中輸入
.read test.sql
即將所有的資料匯入到rui.db 資料庫。
4、列出所有的資料表: .tables
完成上面所有的工作以後,我們就可以列出所有的資料表了
[root@devops-ruifengyun /tmp ]$ sqlite3 rui.db SQLite version 3.7.17 2013-05-20 00:56:22 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .tables ceshi tbl1 sqlite> sqlite>
5、顯示資料庫結構:.schema5就是一些SQL 語句,他們描述了資料庫的結構,如圖
sqlite> .schema CREATE TABLE tbl1(one varchar(10), two smallint); CREATE TABLE ceshi (user text, note text);
6、顯示表的結構:.schema 表名
sqlite> .schema ceshi CREATE TABLE ceshi (user text, note text)
表名
sqlite> .dump tbl1 PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE tbl1(one varchar(10), two smallint); INSERT INTO "tbl1" VALUES('goodbye',20); INSERT INTO "tbl1" VALUES('hello!',10); COMMIT;
再來講解下python sqlite3的用法,其實和mysqldb很像吧,他的文法和mysql差不多
import sqlite3 #原文: xiaorui.cc #链接数据库文,sqlite都是以文件的形式存在的。 #如果数据库文件不存在,回新建一个,如果存在则打开此文件 conn = sqlite3.connect('example') c = conn.cursor() #创建table c.execute('''create table ceshi (user text, note text)''') # 插入数据,执行SQL语句 c.execute('''insert into ceshi (user,note) values('mPfiJRIH9T','mPfiJRIH9T')''') c.execute('''insert into ceshi (user,note) values('7IYcUrKWbw','7IYcUrKWbw')''') c.execute('''insert into ceshi (user,note) values('bXB9VcPdnq','bXB9VcPdnq')''') c.execute('''insert into ceshi (user,note) values('2JFk7EWcCz','2JFk7EWcCz')''') c.execute('''insert into ceshi (user,note) values('QeBFAlYdPr','QeBFAlYdPr')''') c.execute('''insert into ceshi (user,note) values('bDL4T69rsj','bDL4T69rsj')''') c.execute('''insert into ceshi (user,note) values('BOxPqmkEd9','BOxPqmkEd9')''') c.execute('''insert into ceshi (user,note) values('rvBegjXs16','rvBegjXs16')''') c.execute('''insert into ceshi (user,note) values('CWrhA2eSmQ','CWrhA2eSmQ')''') c.execute('''insert into ceshi (user,note) values('qQicfV2gvG','qQicfV2gvG')''') c.execute('''insert into ceshi (user,note) values('s3vg1EuBQb','s3vg1EuBQb')''') c.execute('''insert into ceshi (user,note) values('Lne4xj3Xpc','Lne4xj3Xpc')''') c.execute('''insert into ceshi (user,note) values('PH3R86CKDT','PH3R86CKDT')''') c.execute('''insert into ceshi (user,note) values('HEK7Ymg0Bw','HEK7Ymg0Bw')''') c.execute('''insert into ceshi (user,note) values('lim2OCxhQp','lim2OCxhQp')''') c.execute('''insert into ceshi (user,note) values('kVFfLljBJI','kVFfLljBJI')''') c.execute('''insert into ceshi (user,note) values('Hpbs3VOXNq','Hpbs3VOXNq')''') c.execute('''insert into ceshi (user,note) values('f5ubmznBIE','f5ubmznBIE')''') c.execute('''insert into ceshi (user,note) values('beJCQA2oXV','beJCQA2oXV')''') c.execute('''insert into ceshi (user,note) values('JyPx0iTBGV','JyPx0iTBGV')''') c.execute('''insert into ceshi (user,note) values('4S7RQTqw2A','4S7RQTqw2A')''') c.execute('''insert into ceshi (user,note) values('ypDgkKi27e','ypDgkKi27e')''') c.execute('''insert into ceshi (user,note) values('Anrwx8SbIk','Anrwx8SbIk')''') c.execute('''insert into ceshi (user,note) values('k5ZJFrd8am','k5ZJFrd8am')''') c.execute('''insert into ceshi (user,note) values('KYcTv54QVC','KYcTv54QVC')''') c.execute('''insert into ceshi (user,note) values('Jv6OyfMA0g','Jv6OyfMA0g')''') c.execute('''insert into ceshi (user,note) values('kpSLsQYzuV','kpSLsQYzuV')''') c.execute('''insert into ceshi (user,note) values('u2zkJQWdOY','u2zkJQWdOY')''') c.execute('''insert into ceshi (user,note) values('D0aspFbW8c','D0aspFbW8c')''') c.execute('''insert into ceshi (user,note) values('CwqhvDOrWZ','CwqhvDOrWZ')''') c.execute('''insert into ceshi (user,note) values('Tdy5LA9sWO','Tdy5LA9sWO')''') c.execute('''insert into ceshi (user,note) values('76HnRVbLX0','76HnRVbLX0')''') c.execute('''insert into ceshi (user,note) values('B3aoFibRPV','B3aoFibRPV')''') c.execute('''insert into ceshi (user,note) values('7Q6lNdL5JP','7Q6lNdL5JP')''') c.execute('''insert into ceshi (user,note) values('Hsob6Jyv4A','Hsob6Jyv4A')''') #将变动保存到数据库文件,如果没有执行词语句,则前面的insert 语句操作不会被保存 conn.commit() c.execute('''select * from ceshi ''').fetchall() #得到所有的记录 rec = c.execute('''select * from ceshi''') print c.fetchall()

Tomergelistsinpython,YouCanusethe操作員,estextMethod,ListComprehension,Oritertools

在Python3中,可以通過多種方法連接兩個列表:1)使用 運算符,適用於小列表,但對大列表效率低;2)使用extend方法,適用於大列表,內存效率高,但會修改原列表;3)使用*運算符,適用於合併多個列表,不修改原列表;4)使用itertools.chain,適用於大數據集,內存效率高。

使用join()方法是Python中從列表連接字符串最有效的方法。 1)使用join()方法高效且易讀。 2)循環使用 運算符對大列表效率低。 3)列表推導式與join()結合適用於需要轉換的場景。 4)reduce()方法適用於其他類型歸約,但對字符串連接效率低。完整句子結束。

pythonexecutionistheprocessoftransformingpypythoncodeintoExecutablestructions.1)InternterPreterReadSthecode,ConvertingTingitIntObyTecode,whepythonvirtualmachine(pvm)theglobalinterpreterpreterpreterpreterlock(gil)the thepythonvirtualmachine(pvm)

Python的關鍵特性包括:1.語法簡潔易懂,適合初學者;2.動態類型系統,提高開發速度;3.豐富的標準庫,支持多種任務;4.強大的社區和生態系統,提供廣泛支持;5.解釋性,適合腳本和快速原型開發;6.多範式支持,適用於各種編程風格。

Python是解釋型語言,但也包含編譯過程。 1)Python代碼先編譯成字節碼。 2)字節碼由Python虛擬機解釋執行。 3)這種混合機制使Python既靈活又高效,但執行速度不如完全編譯型語言。

UseeAforloopWheniteratingOveraseQuenceOrforAspecificnumberoftimes; useAwhiLeLoopWhenconTinuingUntilAcIntiment.forloopsareIdealForkNownsences,而WhileLeleLeleLeleLeleLoopSituationSituationsItuationsItuationSuationSituationswithUndEtermentersitations。

pythonloopscanleadtoerrorslikeinfiniteloops,modifyingListsDuringteritation,逐個偏置,零indexingissues,andnestedloopineflinefficiencies


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

記事本++7.3.1
好用且免費的程式碼編輯器