From: Ganesan R <rga...@my...> - 2003-02-14 07:14:26
|
On Thu, Feb 13, 2003 at 11:02:36PM -0800, Bob Terek wrote: > > > I then tried > > > > cursor.execute("SELECT * FROM %s WHERE id = %s" % table, 25) > > > > This doesn't work either because the % operator complains about "not enough > > arguments for format string". I finally worked around by using > > > > Is there a syntactically clear alternative? > > The % operator expects a tuple, so this should work: > > cursor.execute("SELECT * FROM %s WHERE id = %s" % (table, 25)) > > but I haven't tried it of course. That works. But that will disable cursor optimization. From the DB-API-2.0 specification for cursor.execute(): A reference to the operation will be retained by the cursor. If the same operation object is passed in again, then the cursor can optimize its behavior. This is most effective for algorithms where the same operation is used, but different parameters are bound to it (many times). Ganesan -- Ganesan R |