sqlite & python - only pulls the first result
Posted
by pencilNero
on Stack Overflow
See other posts from Stack Overflow
or by pencilNero
Published on 2010-03-31T22:13:34Z
Indexed on
2010/03/31
22:23 UTC
Read the original article
Hit count: 216
This is pretty strange (admitedly, this is my first attempt with python / sqlite), but I can seem to get all of the rows if I do a fetchAll(), but other than that - no matter what I try, always ends up in the db only returning the first row - the second iteration stops because a null is returned. Wondering if there is something wrong with how I am coding this up in python? The db seems ok..
con = sqlite3.connect('backup.db')
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute('select * from tb1;')
for row in cur:
try:
# row = dataCur.fetchone()
#if row == None: break
print type(row)
print ' Starting on: %i' % row[0]
cleaner = Cleaner(scripts=True, remove_tags=['img'], embedded=True)
try:
cleaned = cleaner.clean_html(row[2]) #data stored in second col
cur.execute('update tb1 set data = ? where id = ?;', (cleaned, row[0]))
except AttributeError:
print 'Attribute error'
print ' Ended on: %i' % row[0]
except IOError:
print 'IOexception'
© Stack Overflow or respective owner