1

I can insert text and integer data to MS Access db (.mdb) by using pyodbc package. But now i want to insert Large Binary objects. I have a table that consists ID(COUNTER type), Name(VARCHAR type), File (LONGBINARY type), Author(VARCHAR type) columns. I use that code to insert some text and int data:

cursor.execute("""INSERT INTO table(ID, Name) VALUES(1,'book')""")

After that i used that code but always getting error.

with open('c:/tree.jpg', 'rb') as file:
      binData = file.read()

SQL = """INSERT INTO table VALUES(2,'threePicture', %s, 'Mike')""" %(binData)

cursor.execute(SQL)

The error is: ProgrammingError: ('42000', "[42000])

1 Answer 1

1

I found the solution using ? ? ? characters...

cursor.execute("insert into table values(?, ?, ?, ?)", 2, 'treePicture', pyodbc.Binary(binData), 'Mike')

Use ? chars for values in expression.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.