Can't seem to insert rows into a MySQL table

Anthra Norell anthra.norell at tiscalinet.ch
Tue Mar 15 04:58:49 EST 2005


Very true!
I could verify that cursor.execute () seems to understand  "... %s ...",
..."string"... where print () doesn't.. I didn't know that.
I could also verify that gumfish's ineffective insertion command works fine
for me. (Python 2.4, mysql-3.23.38). So it looks like the problem is with
MySQL (e.g. table name, column names, ...)
Frederic

----- Original Message -----
From: "Marc 'BlackJack' Rintsch" <bj_666 at gmx.net>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Monday, March 14, 2005 11:55 PM
Subject: Re: Can't seem to insert rows into a MySQL table


> In <mailman.410.1110836641.1799.python-list at python.org>, Anthra Norell
> wrote:
>
> > Try to use % instead of a comma (a Python quirk) and quotes around your
> > strings (a MySQL quirk):
> >
> >    cursor.execute("INSERT INTO edict (kanji, kana, meaning) VALUES
('%s',
> > '%s', '%s')" % ("a", "b", "c") )
>
> AFAIK grumfish made the Right Thing™.  If you use '%', some interesting
> things can happen, e.g. if your values contain "'" characters.  The "%s"s
> without quotes and the comma let the DB module format and *escape* the
> inserted values for you in a safe way.
>
> Ciao,
> Marc 'BlackJack' Rintsch
> --
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list