I have a python3 program that I'm making which uses a sqlite database with several tables, I want to create a sele开发者_StackOverflowctor module to allow me to chose which table to pull data from.
I have found out that I can't use parameter substitution for a table name as shown bellow, so I'm looking for some alternative methods to accomplish this.
c.execute("SELECT * FROM ? ", DB)
Any ideas?
Right. You can not use parameter substitution to specify the table. So instead you must do string manipulation:
c.execute("SELECT * FROM {t} ".format(t=tablename))
I don't know if this is a python3 thing but it seems easiest to just do this:
c.execute("SELECT * FROM %s "% tablename)
Blockquote * Right. You can not use parameter substitution to specify the table. So instead you must do string manipulation: c.execute("SELECT * FROM {t} ".format(t=tablename))* Blockquote
Thanks unutbu, this is just what I needed.
精彩评论