我从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行数据?
答案 0 :(得分:0)
请在您的选择查询中使用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感兴趣,请重定向到here