Sqlite & python - only pulls the first result

This is rather strange (it’s possible this is my first attempt with python / sqlite), but I may seem to get all the rows if I do fetchAll (), but other than that, whatever I try always ends in db. only returning the first line - the second iteration stops because null is returned. I wonder if something is wrong with how I code it in python? Db looks fine ..

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'
+3
source share
2 answers

You reuse the same cursor to execute two different queries. Try using two different cursors and see if this solves your problem.

+5
source

, , , .

fetchall, , .

, .

+2

Source: https://habr.com/ru/post/1739384/


All Articles