[DB-SIG] MySQLdb warnings problem
Terry Hancock
hancock@anansispaceworks.com
Mon, 10 Jun 2002 23:40:29 -0700
Hi all,
I'm in the middle of writing a Zope/MySQL project, and
I use a Python/MySQL crawler to do some database
maintenance tasks.
I'm writing this crawler now, and it's my first
experience with "Python Database API 2.0".
I originally posted this question on the main
python list, not knowing where to ask, but I
was refered here, so I hope someone can give me
a clue as to what's going on with this:
The program is fairly long, but what happens is that
it scans the database for entries in a database table
called "user" and calculates some statistics for them
based on other tables. All the retrievals work fine,
but I get a funny traceback when I write the data
back into the user's row in the table:
Traceback (most recent call last):
File "Styx.py", line 258, in ?
styx.crawl( styx.params['P_Styx'], styx_tasks)
File "Crawler.py", line 193, in crawl
task[1](argval) # Operate on it
File "Styx.py", line 165, in compute_user_stats
dbcursor.execute(sqlcmd)
File
"/usr/local/narya/lib/python2.1/site-packages/MySQLdb/cursors.py", line
61, in execute
r = self._query(query)
File
"/usr/local/narya/lib/python2.1/site-packages/MySQLdb/cursors.py", line
168, in _query
rowcount = self._BaseCursor__do_query(q)
File
"/usr/local/narya/lib/python2.1/site-packages/MySQLdb/cursors.py", line
118, in __do_query
self._check_for_warnings()
File
"/usr/local/narya/lib/python2.1/site-packages/MySQLdb/cursors.py", line
150, in _check_for_warnings
raise Warning, self._info
_mysql_exceptions.Warning: Rows matched: 1 Changed: 0 Warnings: 1
For reference, here's a snippet of the code where this
broke:
sqlcmd= """
UPDATE user SET nposts=%d, nrecent=%d, keytopic='%s'
WHERE username='%s'
""" % ( n_posts, n_recent, keytopic, user[0] )
#print sqlcmd
#try:
dbcursor.execute(sqlcmd)
#except:
# pass
[It's already been pointed out to me that dbcursor.execute provides
a safer quoting mechanism than I'm using here -- but as the output
below shows, that's definitely not the problem here.]
As the commented-out lines indicate, I tried ignoring this problem.
Doing so seems to make the program work fine, but I can't figure
out why it should be an issue in the first place (and I generally
prefer not to just ignore warnings, especially without understanding
them).
The thing is, what's the warning message? Nothing was changed
this time, because a previous run already updated the stats (the
first run said "Rows matched: 1 Changed: 1 Warnings: 1").
Uncommenting the print statement shows what the actual SQL was:
UPDATE user SET nposts=7, nrecent=0, keytopic='/'
WHERE username='anonymous'
which looks legit to me, though I'm not really an SQL expert.
So maybe it's raising a warning every time I write to the
database? Why? And more to the point, what is the warning --
shouldn't it be giving me some kind of message from MySQL?
Should I just stick the try-except code back in and forget
about it, or am I missing a step somewhere? Any ideas would
be much appreciated.
Thanks!
Terry
--
------------------------------------------------------
Terry Hancock
hancock@anansispaceworks.com
Anansi Spaceworks
http://www.anansispaceworks.com
------------------------------------------------------