Trouble with Myqsl

Steve Holden sholden at holdenweb.com
Tue Apr 23 08:21:30 EDT 2002


"Fernando Rodríguez" <frr at easyjob.net> wrote ...
>
> I'm using CompatMysqldb from http://sourceforge.net/projects/mysql-python
with
> Python 2.2
>
> Whenever I try to insert some data into a mysql db, I get this 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#26>", 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'
> >>>
>
> The data does get inserted... What am I doing wrong? O:-)
>

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')
)

or, equivalently (but redundantly, unless MySQdb requires executemany()):

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 may or may not make a difference. What's the difference between
CompatMySQLdb and MySQLdb?

regards
 Steve
--

home: http://www.holdenweb.com/
Python Web Programming:
http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list