0

I'm trying to execute the following via Flask's MySQLdb module:

cur.execute("SELECT post_id FROM tbl_post WHERE post_file_path = '%s'", (_filePath,))

Yet I get the following error:

1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'static/uploads/adc67db4-7d23-4bf1-a7ef-7e34dbed246a.jpg''' at line 1"

The query works fine via the command line so I'm fairly certain it's something to do with the way I'm providing my string argument. What am I doing wrong with it?

1 Answer 1

2

You shouldn't quote the placeholder %s, it's done by the database driver. This should work:

cur.execute("SELECT post_id FROM tbl_post WHERE post_file_path = %s", (_filePath,))
Sign up to request clarification or add additional context in comments.

1 Comment

Had seen some examples using quotes, but this works perfectly thanks!

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.