MySQLdb warnings problem

Terry Hancock hancock at anansispaceworks.com
Sat Jun 8 12:03:26 EDT 2002


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", which seems
really overblown and complicated compared to the simple
interface described in O'Reilly's MySQL/mSQL book, or
with the ZSQL interface in Zope. I suppose this is
for the benefit of more complicated RDBMs than MySQL.

Anyway, I hope I'm not making a mistake using it --
I'm just trying to use the most "standard" Python
interface to MySQL, and I'm under the impression that
this is it. Please advise if I'm wrong.

I couldn't find a mysqldb specific mailing list, so I
thought I'd try asking my question here:

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

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?

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 at anansispaceworks.com       
Anansi Spaceworks                 
http://www.anansispaceworks.com 
------------------------------------------------------





More information about the Python-list mailing list