0

I am connecting to an MS SQL Server db from Python in Linux. I am connecting via pyodbc using the FreeTDS driver. When I return a money field from MSSQL it comes through as a float, rather than a Python Decimal.

The problem is with FreeTDS. If I run the exact same Python code from Windows (where I do not need to use FreeTDS), pyodbc returns a Python Decimal.

How can I get back a Python Decimal when I'm running the code in Linux?

mwolfe02
  • 23,787
  • 9
  • 91
  • 161
  • Are you using unixODBC? I wonder if the problem could lie there, I'm pretty sure FreeTDS supports the decimal/money type. – Mark Jul 30 '10 at 15:23
  • I might be. I'm heading home for the weekend now, I'll check into this on Monday. Thanks for the tip. – mwolfe02 Jul 30 '10 at 16:34
  • OK, I'm using unixODBC. I think the problem may have been in my freetds.conf file. I just changed the tds version from 4.2 to 8.0, but I don't know what I need to do to make the change take effect. Do I need to restart apache? Restart something else? – mwolfe02 Aug 02 '10 at 13:48

2 Answers2

1

You could always just convert it to Decimal when it comes back...

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
  • That ends up being a lot of conversions and isn't exactly DRY. I agree that is the fall-back plan, but I'd really like to avoid that. – mwolfe02 Jul 30 '10 at 14:34
0

It was a bug in FreeTDS. The bug has been fixed in the CVS head of FreeTDS as of August 4, 2010 (thanks Freddy Ziglio). See my post on the web2py message board for more info.

mwolfe02
  • 23,787
  • 9
  • 91
  • 161