Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQLite gives me an error near VALUES, what do I do?

I’m trying to select all entries from the table that have user_id = 0 and type that I can give as a parameter.

My code is:

get_all_parking_by_type = 'SELECT * FROM Parking WHERE type = ? and user_id = 0 VALUES (?)'
cursor.execute(get_all_parking_by_type, ('guest'))
guests = cursor.fetchall()

And the error is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sqlite3.OperationalError: near "VALUES": syntax error

It’s probably something stupid but I have no idea how to solve it.

>Solution :

There are two mistakes here:

  • There is no use for the VALUES-syntax, at least it’s not clear what you are trying to accomplish with it; just leave it out
  • The parameter as ('guest') is not actually a tuple but a string inside useless parentheses. You probably meant ('guest', ).

Try

get_all_parking_by_type = 'SELECT * FROM Parking WHERE type = ? and user_id = 0'
# Notice the comma after `'guest'`
cursor.execute(get_all_parking_by_type, ('guest', ))
guests = cursor.fetchall()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading