Reputation: 484
I'm trying to write a Python (2) script that manages a SQLite3 database. I'm having trouble getting all of the rows from the table and looping through them. My table has 218 rows (according to PHP and sqlite3.exe) yet Python only loops through 8.
import sqlite3 as sql
db = sql.connect('database.db')
c = db.cursor()
n = 0
for row in c.execute('select * from table'):
n += 1
print n
What am I doing wrong? Is there some extra step that I need to take to get Python to loop through all of the rows?
Upvotes: 0
Views: 970
Reputation: 3154
I do something like this:
conn = sqlite3.connect(filename)
cursor = conn.cursor()
cursor.execute('SELECT * from tablename')
results = cursor.fetchall()
print '\nindividual records'
for result in results:
print result
Upvotes: 1