Trouble with Myqsl
Fernando RodrÃguez
frr at easyjob.net
Tue Apr 23 09:40:19 EDT 2002
On Tue, 23 Apr 2002 08:21:30 -0400, "Steve Holden" <sholden at holdenweb.com>
wrote:
>I don't think you need the string quotes around the parameter markers - the
>module determines the required type, and in many cases will perform
>conversions for you as necessary. Since you are using a list of tuples, you
>should really be calling executemany() rather than execute, though most DB
>API modules will accept lists of tuples. Try this:
>
>curs.execute(
> """insert into customer_info (email, url, referrer, first_visit)
> values ( %s, %s, %s, %s)""",
> ('billg at microsoft.com', 'www.easyjob.net', 'www.google.com', '2001-03-07
>12:32:00')
>)
It gives an error:
>>> curs.execute("""insert into customer_info (email, url, referrer, first_visit) values ( %s, %s, %s, %s)""", ('billg at microsoft.com', 'www.easyjob.net', 'www.google.com', '2001-03-07 12:32:00'))
Traceback (most recent call last):
File "<pyshell#53>", line 1, in ?
curs.execute("""insert into customer_info (email, url, referrer,
first_visit) values ( %s, %s, %s, %s)""", ('billg at microsoft.com',
'www.easyjob.net', 'www.google.com', '2001-03-07 12:32:00'))
File "D:\ARCHIV~1\Python22\Lib\site-packages\CompatMysqldb.py", line 230, in
execute
raise error, msg
mysqldb.error: (1064, "You have an error in your SQL syntax near
'@microsoft.com, www.easyjob.net, www.google.com, 2001-03-07 12:32:00)' at
line 1")
>>>
If I add the string quotes again, I get the same AttributeError exception I
was getting before:
>>> curs.execute("insert into customer_info (email, url, referrer, first_visit) values ( '%s', '%s', '%s', '%s')", ('billg at microsoft.com', 'www.easyjob.net', 'www.google.com', '2001-03-07 12:32:00'))
Traceback (most recent call last):
File "<pyshell#56>", line 1, in ?
curs.execute("insert into customer_info (email, url, referrer,
first_visit) values ( '%s', '%s', '%s', '%s')", ('billg at microsoft.com',
'www.easyjob.net', 'www.google.com', '2001-03-07 12:32:00'))
File "D:\ARCHIV~1\Python22\Lib\site-packages\CompatMysqldb.py", line 227, in
execute
af =af+self.__res.affectedrows()
AttributeError: 'NoneType' object has no attribute 'affectedrows'
>>>
>It may or may not make a difference. What's the difference between
>CompatMySQLdb and MySQLdb?
I'm not sure. I haven't been able to find MySQLdb. I found this Compat thing
in MySQL-python-0.9.1.win32-py2.2.exe at
http://sourceforge.net/project/showfiles.php?group_id=22307&release_id=51760
Where can I find MySQLdb for win32 _and_ Linux? O:-)
-----------------------
Fernando Rodriguez
More information about the Python-list
mailing list