I'm fetching the list of full data from a sqlite3 database. I want to pull 20 rows of data for each channel, but on my code it will fetch all of data for each channel.
Here is the code:
#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]
Can you please show me how I could fetch 20 rows of data from a database without fetching all of the data for each channel??
Please use limit 20
in your select query.
cur.execute('SELECT channel, title, start_date, stop_date FROM programs where channel=? limit 20', [channel])
We can also make it with 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)
If you are insterested in python sqlite3, please redirect to here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.