I want to retrieve the 100 first rows of my Sqlite3 database:
connection = sqlite3.connect('aktua.db')
cursor = connection.cursor()
print('Actual \tCliente \tHistórica')
cursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE '%K'").fetchmany(size=100)
for row in cursor:
print('%s \t%s \t%s' % row)
cursor.close()
connection.close()
My code retrieves all rows of the database (+4000).
I've read sqlite3.Cursor.fetchmany Docs and SQLite Python Tutorial.
What's wrong?
Use this to limit the sql selection:
"SELECT * FROM Referencias WHERE r_aktua LIKE '%K' LIMIT 100"
Or changue your code to:
rows = cursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE '%K'").fetchmany(size=100)
for row in rows:
print('%s \t%s \t%s' % row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With