My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 295: decimal fields don't work with Python 3.3
3 people starred this issue and may be notified of changes. Back to list
Status:  Investigating
Owner:  ----


 
Reported by davidp.r...@gmail.com, Oct 31, 2012
What steps will reproduce the problem?

Running Python 3.3 with pyodbc-3.0.6


1. run sqlservertests.py from the pyodbc test suite


What is the expected output? 

Decimal tests pass

What do you see instead?
ERROR: test_decimal_1_0_n (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_1_0_p (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_38_0_n (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_38_0_p (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_38_10_n (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_38_10_p (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_38_38_n (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_38_38_p (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_6_0_p (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_6_2_p (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_6_4_n (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_6_6_n (__main__.SqlServerTestCase)
    self._decimal(p, s, n)
  File "sqlservertests.py", line 378, in _decimal
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ERROR: test_decimal_e (__main__.SqlServerTestCase)
Ensure exponential notation decimals are properly handled
  File "sqlservertests.py", line 405, in test_decimal_e
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]


What version of the product are you using? On what operating system?

python:  3.3.0 (default, Sep 29 2012, 15:50:43) 
[GCC 4.7.1 20120721 (prerelease)]
pyodbc:  3.0.6 /usr/lib/python3.3/site-packages/pyodbc.cpython-33m.so
odbc:    03.52
driver:  libtdsodbc.so 0.91.dev.20120312
         supports ODBC version 03.50
os:      Linux
unicode: Py_Unicode=4 SQLWCHAR=2

Please provide any additional information below.

tests pass with Python 2.7.3 and pyodbc-3.0.6




Nov 2, 2012
#1 davidp.r...@gmail.com

I have looked into this a developed the attached patch which seems to fix this problem.

A number of the other tests fail but most of theses failures are: type(bytearray) != type(bytes).  This of course is true but the two types are interoperable so maybe these tests need to be changed.  I think most of the other failures pre-date Python 3.3.

sqlwchar.patch
692 bytes   View   Download
Dec 27, 2012
#2 lukas.l...@gmail.com
Couldnt it just read

#if PY_VERSION_HEX >= 0x03030000
return PyUnicode_FromKindAndData(SQLWCHAR_SIZE, sz, cch);
#endif

?
Dec 27, 2012
#3 davidp.r...@gmail.com

You are correct.  For some reason, I wanted to handle the '1' case but, if SQL wide characters are always wider than 1 byte (which must be true or they wouldn't be 'wide'), that doesn't count.  

Simpler is better.




Mar 28, 2013
Project Member #4 mkleehammer
(No comment was entered for this change.)
Status: Investigating
Jan 15, 2014
#5 netezza...@gmail.com
Decimal fields don't work with Python 2.7.5 on Linux 64 bit with Pyodbc 3.07 as well. Do you know if there is any similar patch for Python 2.7.5 or any other solution available that can solve the problem?
Aug 7, 2014
#6 rahul.ch...@gmail.com
We are facing the same problem while reading the NUMERIC(X,Y) data from Vertica using pyodbc 3.0.7 with python 2.7.2 on Red Hat Enterprise Linux Server release 5.10 (Tikanga). 

The result we see as an output is the first digit of the actual data in the database cell. If the value in the cell is less than '0' for example "0.59", then we get the following error:

File "/usr/local/lib/python2.7/decimal.py", line 548, in _new_
"Invalid literal for Decimal: %r" % value)
File "/usr/local/lib/python2.7/decimal.py", line 3844, in _raise_error
raise error(explanation)

And the saddest part is, the same setup works fine with python 2.7.2 and pyodbc 2.1.11. We are not sure what got added or removed from pyodbc 2.1.11 to pyodbc 3.0.7 which is making the conversion of SQL_NUMERIC to decimal.Decimal to fail. 

Powered by Google Project Hosting