Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite & python - only pulls the first result

Tags:

python

sqlite

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'
like image 535
pencilNero Avatar asked Mar 31 '10 22:03

pencilNero


People also ask

What is SQLite used for?

SQLite is used to develop embedded software for devices like televisions, cell phones, cameras, etc. It can manage low to medium-traffic HTTP requests. SQLite can change files into smaller size archives with lesser metadata. SQLite is used as a temporary dataset to get processed with some data within an application.

What is difference between SQL and SQLite?

SQL is Structured Query Language which is used with databases like MySQL, Oracle, Microsoft SQL Server, IBM DB2, etc. It is not a database itself. SQLite is a portable database resource. You have to get an extension of SQLite in whatever language you are programming in to access that database.

Is SQLite SQL or MySQL?

Both MySQL and SQLite are forms of a Relational Database Management System (RDBMS). These are based on the Structured Query Language (SQL).

Is SQLite better than SQL?

All data is handled inside your process solely for your application. SQLite is generally a lot faster than MS SQL Server if dealing with small-size databases. SQLite can be integrated with different programming languages and environments including . NET.


1 Answers

You are reusing the same cursor to execute two different queries. Try using two different cursors and see if that solves your problem.

like image 70
Mark Byers Avatar answered Sep 26 '22 14:09

Mark Byers