SQL Query via python

Jeff Elkins jeffelkins at earthlink.net
Fri May 20 23:57:01 EDT 2005


I'm attempting to pass an SQL query via the console:

$ ./getbd month 05

The arguments get seem to passed correctly (via print statements) and then:

    cursor.execute ("""
                     SELECT name, month, day ,category, city FROM bday
                     WHERE %s = %s
                   """,(arg1,arg2))

No results. However, if I hardcode the WHERE argument with a field name:

 cursor.execute ("""
                     SELECT name, month, day ,category, city FROM bday
                     WHERE month = %s
                   """,(arg2))

It works.

How can I code the left side of the WHERE clause so I can pass an arbitrary 
field name to search on?


Thanks,

Jeff Elkins





More information about the Python-list mailing list