Re: [pysqlite] Bind a table name using APSW

Gerhard Häring <[email protected]> Thu, 17 Jul 2008 11:29:02 +0200
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
Jason Chang wrote:
> Hi all,
> I'm trying out APSW 3.5.9-r2. I'd like to parameterize a SELECT query
> so that the table name in the FROM clause can be bound at runtime.
> Something like:
> SELECT count(idFile) FROM ? [...]

SQL parameters don't work like this. SQL parametrization (no matter 
which database) only works in places where you could use literals.

As a rule of thumb: you can use SQL parameters everywhere where you 
could also write a "value".

If you need this, then you need to do it in two steps:

table_name = "table1"
sql = "select count(idFile) from %s where col1=?"
sql = sql % table_name
cursor.execute(sql, ("blabla",))

HTH,

-- Gerhard