您好,登錄后才能下訂單哦!
如何在python3中使用sqlite3限制條件查詢?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
import json import sqlite3 import re import argparse def Get(db_file): conn = sqlite3.connect(db_file) cur = conn.cursor() print("5555555") value1=(60)# this is must be () cur.execute("select * from exception where AGV_ID=(%s)" %(value1)) #cursor.execute("insert into exception values('%s', '%s','%s' ) " %(start_time ,ID ,infomation)) result= cur.fetchall() print("result:",result) for i in result: print(i) print("******************************888") def get_agv_id(db_file): try: conn = sqlite3.connect(db_file) cur = conn.cursor() cur.execute("select * from exception where AGV_ID=51") #print( cur.fetchall()) result= cur.fetchall() for i in result: print(i) except sqlite3.Error,e: print(e) if __name__ == '__main__': parser = argparse.ArgumentParser(description='check the information of db') #parser.add_argument('-h', '--help', help='Statistics for abnormal information') parser.add_argument('-n', '--name', help=' the db of name ') args = vars(parser.parse_args()) db_name = args['name'] print("db_name:",db_name) conn = sqlite3.connect('db_name') cursor = conn.cursor() Get('fitkits.db') get_agv_id('fitkits.db') conn.commit() conn.close() print('DONE!') print("666")
補(bǔ)充:python + sqlite3 基本操作
import sqlite3 # 連接數(shù)據(jù)庫(如果不存在則創(chuàng)建) conn = sqlite3.connect('test.db') print("Opened database successfully") # 創(chuàng)建游標(biāo) cursor = conn.cursor() ... # 關(guān)閉游標(biāo) cursor.close() # 提交事物 conn.commit() # 關(guān)閉連接 conn.close()
... # 創(chuàng)建游標(biāo) cursor = conn.cursor() # 創(chuàng)建表 sql = 'CREATE TABLE Student(id integer PRIMARY KEY autoincrement, Name varchar(30), Age integer)' cursor.execute(sql) # 提交事物 conn.commit() ...
... # 創(chuàng)建游標(biāo) cursor = conn.cursor() # 插入數(shù)據(jù) sql = "INSERT INTO Student(Name, Age) VALUES(\'love\', 22)" cursor.execute(sql) # 插入數(shù)據(jù) 2 data = ('love2', 2221) # or ['love2', 2221] sql = "INSERT INTO Student(Name, Age) VALUES(?, ?)" cursor.execute(sql, data) # 提交事物 conn.commit() ...
... # 創(chuàng)建游標(biāo) cursor = conn.cursor() # 查詢數(shù)據(jù) sql = "select * from Student" values = cursor.execute(sql) for i in values: print(i) # 查詢數(shù)據(jù) 2 sql = "select * from Student where id=?" values = cursor.execute(sql, (1,)) for i in values: print('id:', i[0]) print('name:', i[1]) print('age:', i[2]) # 提交事物 conn.commit() ...
自增字段起始位置
# 設(shè)置起始值為1 update sqlite_sequence SET seq = 0 where name = '表名'; # 設(shè)置全部表起始值為默認(rèn)值 delete from sqlite_sequence where name='TableName'; --注意表名區(qū)分大小寫
關(guān)于如何在python3中使用sqlite3限制條件查詢問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。