The following use of the API with MySQL works fine
> items = [1, 2]
> execute('SELECT * from table1 WHERE field1 IN %s', (items,))
resultant query string: SELECT * from table1 WHERE field1 IN ('1', '2')
By contrast, the following yields the message "error in your SQL syntax"
> items = [1]
> execute('SELECT * from table1 WHERE field1 IN %s', (items,))
resulting query string: SELECT * from table1 WHERE field1 IN ('1',)
Thus it seems the only way to manage this situation is to use this
stilted construction:
> if len(items)==1:
> execute('SELECT * from table1 WHERE field1 IN (%s)', items[0])
> else:
> execute('SELECT * from table1 WHERE field1 IN %s', (items,))
Is this just a shortcoming in how the API handles formatting of lists
or is there a cleaner way to handle this?
_______________________________________________
DB-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/db-sig