How do I get around not being able to parse a table name into a python sqlite query?

后端 未结 3 524
不知归路
不知归路 2021-01-23 21:49

I have a python3 program that I\'m making which uses a sqlite database with several tables, I want to create a selector module to allow me to chose which table to pull data from

相关标签:
3条回答
  • 2021-01-23 22:13

    I don't know if this is a python3 thing but it seems easiest to just do this:

    c.execute("SELECT * FROM %s "% tablename)
    
    0 讨论(0)
  • 2021-01-23 22:16

    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.

    0 讨论(0)
  • 2021-01-23 22:29

    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))
    
    0 讨论(0)
提交回复
热议问题