0

I'm trying to query a database with the following code:

def check_entry(self, contest_id, number):
    print("Contest id: {0}, Number: {1}".format(contest_id, number))
    self._db_cursor.execute("""SELECT * FROM Entry WHERE ContestID LIKE ? AND Number Like ?""",
                            (contest_id, number))
    row = self._db_cursor.fetchone()
    if row:
        return row
    else:
        return None

This had been consistently working, but I changed seemingly unrelated things in the code, and now I'm receiving this error:

pypyodbc.ProgrammingError: (u'42000', u'[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Argument data type image is invalid for argument 2 of like function.')

The error message is straightforward enough, but nothing of datatype image should have been near this function. Originally I was passing an object which did have image data attached. I put a break point in the code and verified that the contest_id and number properties on the object were the correct datatypes. They were, but to be safe I passed them in separately (unattached to an object), and also printed them to the console. Neither are datatype image when the error occurs (or ever), which is why I'm totally lost for how to fix it. Does anyone know the possible cause of this?

EDIT: I've updated the following line:

self._db_cursor.execute("""SELECT * FROM Entry WHERE ContestID LIKE ? AND Number Like ?""",
                        (int(contest_id), int(number)))

and the error is still occuring. There's a close to 0% chance image data is being passed to this. Even then image data that does exist is varbinary(max) since image datatype is deprecated.

M Dillon
  • 164
  • 1
  • 8
  • Sounds like one of those "why the **** is this not working?" moments. Then you come back an hour later and re-assess. Everything in your question seems to mount up to this being a genuine error and somewhere something got through your gaze. – roganjosh Feb 09 '18 at 21:09
  • can we see the result from `print("Contest id: {0}, Number: {1}".format(contest_id, number))` – JacobIRR Feb 09 '18 at 21:10
  • These are the last 5 lines of the print: `Contest id: 289, Number: 21 Contest id: 289, Number: 20 Contest id: 289, Number: 19 Contest id: 289, Number: 18 Contest id: 289, Number: 17` The last one is the parameters it failed on. – M Dillon Feb 09 '18 at 21:13

0 Answers0