[Tutor] mod_python & mysqldb problem
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Feb 23 22:04:43 CET 2006
On Thu, 23 Feb 2006, Patty wrote:
> def addpercent(mp, lp):
> conn = MySQLdb.connect(host = "localhost", user = "root", passwd =
> "",db ="my_db")
> cursor = conn.cursor()
> cursor.execute ("""
> UPDATE targets
> SET mario_percent = %d, lizard_percent = %d
> WHERE target_name = 'anyname'
> """, (mp, lp))
> db.commit()
> cursor.close()
> db.close()
Hi Patty,
Does this code work outside of the context of mod_python?
There's something slightly suspicious here in the use of the '%d' format
string: I'm not sure MySQLdb will accept it. Let me check...
According to the DB API on parameter styles:
"""
paramstyle
String constant stating the type of parameter marker
formatting expected by the interface. Possible values are
[2]:
'qmark' Question mark style,
e.g. '...WHERE name=?'
'numeric' Numeric, positional style,
e.g. '...WHERE name=:1'
'named' Named style,
e.g. '...WHERE name=:name'
'format' ANSI C printf format codes,
e.g. '...WHERE name=%s'
'pyformat' Python extended format codes,
e.g. '...WHERE name=%(name)s'
"""
(http://www.python.org/peps/pep-0249.html)
So '%s' acts as a placeholder --- a parameter marker --- where MySQLdb
will later substitute parameters into. So I'm not certain that '%d' will
work properly.
In any case, you should never get a segfault in Python code, so something
strange is happening. Try seeing if your code works outside of mod_python
first; that'll give us at least a little more assurance that it isn't
MySQLdb that's doing funny things. You might also want to talk with the
mod_python folks, since they'll probably be able to give you ideas on how
to get better debugging output here.
Good luck to you!
More information about the Tutor
mailing list