curious paramstyle qmark behavior

Diez B. Roggisch deets at nospam.web.de
Fri Oct 20 22:56:43 CEST 2006


BartlebyScrivener schrieb:
> With
> 
> aColumn = "Topics.Topic1"'
> 
> The first statement "works" in the sense that it finds a number of
> matching rows.
> 
> c.execute ("SELECT Author, Quote, ID, Topics.Topic1, Topic2 FROM
> QUOTES7 WHERE " + aColumn + " LIKE ?", ("%" + sys.argv[1] + "%",))
> 
> I've tried about 20 different variations on this next one. And it finds
> 0 records no matter what I do. Is there some violation when I use two
> qmarks?
> 
> c.execute ("SELECT Author, Quote, ID, Topics.Topic1, Topic2 FROM
> QUOTES7 WHERE ? LIKE ?", (aColumn, "%" + sys.argv[1] + "%"))
> 
> I'm using mx.ODBC and Python 2.4.3 to connect to an MS Access DB.

Parameter passing only works for literal values - not for creating sql 
statements.

So, actually your first version is the correct version.

Diez



More information about the Python-list mailing list