1

I am trying to do something like this

cur.execute('''SELECT ID FROM ? WHERE Name = ?''', (var1,var2) )

but got a error message of syntax error near "?"

I have also tried

 cur.execute("SELECT ID FROM" + var1 + "WHERE Name = ?", (var2,))

same error happened

asked Feb 5, 2016 at 7:03

1 Answer 1

1

You can't use placeholder for names of columns or tables.

The second example fails because of missing spaces. Correct to:

cur.execute("SELECT ID FROM " + var1 + " WHERE Name = ?", (var2,))
answered Feb 5, 2016 at 7:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.