pythonsqlsqlitecursor

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:

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:

    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()