Search code examples
ms-accesspypyodbc

PypyODBC with parameters: [ODBC Microsoft Access Driver] Too few parameters. Expected 3 (not a Date issue)


I'm setting up small RestFul API based on Flask to have an access to a DB. I've tackled GET and POST methods which are working great, but having issues with PUT.

I've already swapped pyodbc to pypyodbc since it actually have 'update' methods. I'm running it on 10.0.17134.1 (tried 14.00.7010.1000 which is older) ODBC 32-bit driver with 32-bit python 3.7.2 on Windows 10 machine.

def put(self, code_id):
        query = request.get_json()[0]
        sql = 'UPDATE `employees` SET `employee`=?, `access_level`=? WHERE `CODE`="' + code_id+ '";'
        params = [query['Employee'], query['Access level']]

        cursor.execute(sql, params)
        return Response(status=200)

I'm getting next error: pypyodbc.DatabaseError: ('07002', '[07002] [ODBC Microsoft Access Driver] Too few parameters. Expected 3

I've tried to send only one parameter to change single field, but still getting the same error with a little twist - it'll expect you to send 2 parameters instead. If you add one extra parameter to the 'params' list, then you'll get pypyodbc.ProgrammingError: ('HY000', 'The SQL contains 2 parameter markers, but 3 parameters were supplied') error.

Also, column and table names in DB are in Russian (which I translated) and cannot be changed. Therefore quotation marks are neccesary when making a query.

PS. INSERT and SELECT queries are working just great.


Solution

  • OK, I finally got it.

    So, apparently WHERE clause requires single quotes (') instead of double ones (").

    When argument is enclosed in those, it works like a charm.