2

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.

0

2 Answers 2

0

Try this

cur.execute("PRAGMA table_info({})".format(x))
Sign up to request clarification or add additional context in comments.

Comments

-2

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

This worked. Thank You!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.