[pysqlite] [APSW 3.6.3-r1] cursor.execute only runs once?
Fred <[email protected]> Sat, 25 Oct 2008 03:10:30 +0200
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Hello
I'm not a Python expert, and lost as to why APSW only runs the INSERT
once and then exits the loop although there are more records to be
read from the SELECT:
========
import urllib
import re
import apsw
url =
"http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Daps&field-keywords="
pattern = 'class="srTitle">(.+?)</span>'
connection=apsw.Connection("mybooks.sqlite")
cursor=connection.cursor()
p = re.compile(pattern)
for row in cursor.execute("SELECT isbn FROM books WHERE title IS NULL"):
if row[0]:
isbn = row[0]
f = urllib.urlopen(url + isbn)
page = f.read()
f.close()
m=p.search(page,re.I | re.S | re.M)
if m:
print "Found ISBN " + isbn + " = " + m.group(1)
sql = "UPDATE books SET title='%s' WHERE isbn='%s'" % (m.group(1),isbn)
#Why does it end after updating just one record?
try:
cursor.execute(sql)
except:
print "Error"
else:
print "Nothing found for ISBN " + isbn
connection.close(True)
========
Any idea? Thank you.