5

I am using python 2.7 for a specific job. I am connecting to MSSQL Server (2008) using FreeTDS. I can make some simple select queries but when I try to run a parametrised query I got an error:

('HY004', '[HY004] [FreeTDS][SQL Server]Invalid data type (0) (SQLBindParameter)')

Here is my query:

query = u"UPDATE table SET column1=? WHERE column2=?"
cursor.execute(query,[param1, param2])

However the same code on live works fine.

I have skimmed so many thread in various forums but they all seem misleading and I am really confused.

What is my actual problem and what do you suggest?

Edit: I've added query.

huzeyfe
  • 3,554
  • 6
  • 39
  • 49

1 Answers1

10

I know this is a super old thread, but I came across this same problem and the solution for me was to type cast the variables. For instance:

query = u"UPDATE table SET column1=? WHERE column2=?"

cursor.execute(query,[str(param1), str(param2)])

In this case it doesn't really matter what type the parameters are as it will be converted to a string.

Matt Binford
  • 620
  • 8
  • 15