Can't seem to insert rows into a MySQL table

Marc 'BlackJack' Rintsch bj_666 at
Mon Mar 14 23:55:22 CET 2005

In <mailman.410.1110836641.1799.python-list at>, Anthra Norell

> 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.

	Marc 'BlackJack' Rintsch

More information about the Python-list mailing list