[英]Fetch the data from rows with limit
我正在從sqlite3數據庫中獲取完整數據列表。 我想為每個通道提取20行數據,但是在我的代碼中,它將獲取每個通道的所有數據。
這是代碼:
#get the programs list
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', 'source.db'))
conn = database.connect(profilePath)
cur = conn.cursor()
cur.execute('SELECT channel, title, start_date, stop_date FROM programs where channel=?', [channel])
programList = list()
programs = cur.fetchall()
start_pos = 375 # indent for first program
for ind, row in enumerate(programs):
title = row[1]
您能告訴我如何從數據庫中獲取20行數據而不獲取每個通道的所有數據嗎?
請在您選擇的查詢中使用limit 20
。
cur.execute('SELECT channel, title, start_date, stop_date FROM programs where channel=? limit 20', [channel])
我們也可以使用python sqlite做到這一點
#get the programs list profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', 'source.db')) conn = database.connect(profilePath) cur.execute('SELECT channel, title, start_date, stop_date FROM programs where channel=?', [channel]) for id, row in enumerate(programs): if id == 20: break else: print(id, row)
如果您對python sqlite3感興趣,請重定向到此處
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.