dailey007 / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

decimal fields don't work with Python 3.3 #295

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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

Original issue reported on code.google.com by davidp.r...@gmail.com on 31 Oct 2012 at 6:12

GoogleCodeExporter commented 8 years ago

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.

Original comment by davidp.r...@gmail.com on 2 Nov 2012 at 5:28

Attachments:

GoogleCodeExporter commented 8 years ago
Couldnt it just read

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

?

Original comment by lukas.l...@gmail.com on 27 Dec 2012 at 11:48

GoogleCodeExporter commented 8 years ago

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.

Original comment by davidp.r...@gmail.com on 27 Dec 2012 at 5:00

GoogleCodeExporter commented 8 years ago

Original comment by mkleehammer on 29 Mar 2013 at 12:11

GoogleCodeExporter commented 8 years ago
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?

Original comment by netezza...@gmail.com on 15 Jan 2014 at 2:33

GoogleCodeExporter commented 8 years ago
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. 

Original comment by rahul.ch...@gmail.com on 7 Aug 2014 at 10:20