Basiclly I wish to use a string I have saved in a python variable as my parameter 'table-name' in "PRAGMA table_info(table-name);"
import sqlite3
connect = sqlite3.connect('exampleDB.sqlite')
cur = connect.cursor()
x = 'a string'
cur.execute("PRAGMA table_info(?)", (x,))
This was my first idea. Which did not work and neither did:
cur.execute("PRAGMA table_info(table) VALUES (?)", (x,))
Which was an idea I got from here.
Just putting the variable in there like so:
cur.execute("PRAGMA table_info(x))
also proved fruitless.
Any ideas? This is my first time posting here so feel free to lecture me on how or where I should have posted this differently should you see fit.
2 Answers 2
Try this
cur.execute("PRAGMA table_info({})".format(x))
answered Jul 27, 2018 at 14:22
Martin
4591 gold badge8 silver badges27 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You want to do the following:
cur.execute("PRAGMA table_info(" + x + ")")
Note, this is a duplicate of Python sqlite3 string variable in execute
1 Comment
Dario K.
This worked. Thank You!
default