SQLite是一套輕量資料庫,對我而言幾乎用不到,但因為工作需要,還是找一些有關SQLite資訊,把有用的資料統整為我工作上使用的資料。
系統:ubuntu 16.04 and windows server 2010
sqlite 使用方法如下:
參考網址:https://www.sqlite.org/cli.html
sqlite指令語法
.tables查看tables .separator 轉換符號(, |) .import sqlite基本功能匯入 .quit 跳出sqlite命令列 .schema 查詢schema |
sqlite> .tables Devices sqlite> .separator "," 改成, sqlite> .import UUID.csv Devices 輸入 uid 到Devices sqlite> .separator "|" 改回|(或跳出去,再回來也可以) sqliite> .quit .schema create table tbl1(one varchar(10), two smallint) CREATE TABLE tbl2 ( f1 varchar(30) primary key, f2 text, f3 real )
SQL基本語法
select 列出資料
delete 刪除tables資料
select * from Devices delete from Devices
實務狀況
有用python抓資料回存sqlite,若長時間存至sqlite檔案,會導致檔案過大,造成效能低落,評估過此資料是一次性資料,寫進去不會再查,可以設計寫入一天之後,再用windows task scheduler方式將資料清除。所以會寫一個Dos batch file。
若有人需要知道sqlite3 windows 安裝方式,可以參考以下連結,我就是用這個參考建置起來的。
參考網址如下:https://bigcode.wordpress.com/2010/12/12/accessing-sqlite-from-a-dos-batch-file/
參考網址其中的內容:
echo @echo SELECT name from person where id=^%1^;^| sqlite3.exe mydatabase.sqlite > person.bat echo @echo SELECT phone from person where id=^%1^;^| sqlite3.exe mydatabase.sqlite > phone.bat
修改成我的方式,直接把我的部份改成batch 文字檔,當要執行時,就執行batch檔案即可 ,加上用windows task scheduler定時刪除。就不會有檔案過大問題。
@echo delete from xxxxx;| sqlite3 D:\script\xxxxx.sqlite