3

I have the following Python code and it gives me errors when I execute it, the error says

sqlite3.OperationalError: near "%": syntax error

statement = "INSERT INTO %s (%s) VALUES " % (table,columns) + "(%s,%s,%s);"
cur.execute(statement, (index,fullpath,filename))

1 Answer 1

2

SQL parameters are handled by the database, not by Python, so the syntax is not necessarily the same as Python's.

In SQLite (and most other databases), parameters are marked with a ?:

statement = "INSERT INTO %s (%s) VALUES (?,?,?);" % (table,columns)
cur.execute(statement, (index,fullpath,filename))
Sign up to request clarification or add additional context in comments.

1 Comment

thank you it worked, replacing the +"(%s,%s,%s);" with ? did the trick

Your Answer

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.