Why Doesn't This MySQL Statement Execute?

Chris Angelico rosuav at gmail.com
Tue Dec 18 23:49:41 EST 2012


On Wed, Dec 19, 2012 at 2:57 PM, John Gordon <gordon at panix.com> wrote:
> In <mailman.1037.1355875874.29569.python-list at python.org> Tom Borkin <borkintom at gmail.com> writes:
>
>> Actually, what I originally had was:
>> cursor.execute("""insert into interactions values(Null, %s, "Call Back",
>> %s)""", (i_id, date_plus_2))
>> and that didn't work, either. I tried your variation like:
>> cursor.execute("""insert into interactions values(Null, %s, "Call Back",
>> %s)""" % (i_id, date_plus_2))
>> and no cigar :(
>> Tom
>
> Have you tried using single-quotes around Call Back, instead of
> double quotes?  I've noticed that SQL statements prefer single-quoted
> strings (although that may be Oracle specific, as that's all I've really
> worked with).

The SQL standard specifies single quotes, but MySQL and the SQL
standard aren't always on speaking terms. It depends on the MySQL
settings as to whether "asdf" means 'asdf' or means a column named
asdf.

But if that's what the problem is, there ought to be an exception
coming back, surely? I'm not familiar with the Python MySQL bindings,
but that's what I would expect.  What, specifically, does "no cigar"
mean? It executes without errors but does nothing? It purchases a gun,
aims at your shoe, and pulls the trigger?

ChrisA



More information about the Python-list mailing list