Lie Hetland book: Beginning Python..
Scott David Daniels
scott.daniels at acm.org
Fri Nov 11 12:15:18 EST 2005
Magnus Lycka wrote:
> Vittorio wrote:
> Using the same symbol for both string substitutions and SQL placeholder
> such as pysqlite 1 and the MySQL interface does, is not really a bright
> idea in my opinion. Who thinks this is pretty?
>
> sql = "SELECT %s FROM %s WHERE %s = %%s"
> cur.execute(sql % (col,table,search_col), (param,))
>
> I think it's less confusing with:
>
> sql = "SELECT %s FROM %s WHERE %s = ?"
> cur.execute(sql % (col,table,search_col), (param,))
>
or you could use:
sql = "SELECT %s FROM %s WHERE %s = %s"
cur.execute(sql % (col,table,search_col, '%s'), (param,))
which I like better, because you don't have to read
extremely carefully for the double-percents.
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list