python下的sqlite使用

2021-09-17 22:11:07 字數 1324 閱讀 5290

環境:python2.7

在sqlite中有64位的 rowid,rowid預設是自增的。我們用這個特性,來處理我們的增量資料。

建立乙個sqlite記錄資料

# coding=utf-8

import sqlite3

conn0 = sqlite3.connect('local_info.db')

# 獲取表名列表

tables = conn0.execute("select tbl_name from sqlite_master where type='table'")

# 如果表不存在,則建立表

if ('device_rowid_table',) not in list(tables):

conn0.execute('''create table device_rowid_table

(# 裝置列表

device char(20) not null,

# 此前處理過的最大rowid

max_rowid int not null

);''')

# 插入一條資料:假設,我們已經處理了3fa5684f7d53裝置中的前10條資料

conn0.execute('insert into device_rowid_table (device, max_rowid) values ("3fa5684f7d53", 40)')

conn0.commit()

device_id = '3fa5684f7d53'

max_rowid = 0

for device, rowid in conn0.execute('select * from device_rowid_table'):

if device==device_id:

max_rowid = rowid

print max_rowid

conn1 = sqlite3.connect('3fa5684f7d53_1479459121.18.db')

row_num = conn1.execute('select count(*) from snsinfo')

print list(row_num)

conn1.execute('delete from snsinfo where rowid<{}'.format(max_rowid))

conn1.commit()

row_num = conn1.execute('select count(*) from snsinfo')

print list(row_num)

php sqlite PHP的SQLite使用示例

本文概要 對於php連線sqlite資料庫,你必須有php和sqlite,你的系統上安裝。如果沒有安裝原始碼,首先使用下面的命令安裝原始碼 sudo apt get install sqlite3 libsqlite3 dev 安裝sqlite的php連線驅動 sudo apt install ph...

Python學習筆記 SQLite資料庫使用

在使用sqlite前,我們先要搞清楚幾個概念 1 表是資料庫中存放關係資料的集合,乙個資料庫裡面通常都包含多個表,表和表之間通過外來鍵關聯。2 要操作關聯式資料庫,首先需要連線到資料庫,乙個資料庫連線稱為connection 3 連線到資料庫後,需要開啟游標,稱之為cursor,游標提供了一種對從表...

android 簡單書庫操作 SQLite使用

sqlite資料庫是一種輕量級資料庫,它具備跨平台,多語言操作等優點,它廣泛用於包括瀏覽器 ios,android以及一些便攜需求的小型web應用系統。它具備占用資源低,處理速度快等優點。1.首先定義乙個sqliteopenhelper幫助類 sqliteopenhelper是sqlitedatab...