Question

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?

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top