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:
sqlite3.OperationalError: near "VALUES": syntax error
It's probably something stupid but I have no idea how to solve it.
There are two mistakes here:
VALUES
-syntax, at least it's not clear what you are trying to accomplish with it; just leave it out('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()