tmolomby / pyodbc

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

Decimal separator problems with DB2 #289

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi there!

I already wrote an answer to #14, but since the issue was already closed, I'm 
doing a new bug report now :)

pyodbc works nicely with DB2, thank you! However, there are still some problems 
with the Decimal type.

What steps will reproduce the problem?
1. Put this in `test-pyodbc.py`:

import pyodbc

conn = pyodbc.connect('DSN=MYDATABASE')
cur = conn.cursor()

print cur.execute('SELECT 40.5 - 1 FROM SYSIBM.SYSDUMMY1').fetchone()

2. Run `LC_ALL=C python test-pyodbc.py`, output is `(Decimal('39.5'),)`
3. Run `LC_ALL=de_DE.utf8 python test-pyodbc.py`, output is `(Decimal('395'),)`
4. Install ibm_db, put this in test-ibmdbsa.py:
import ibm_db

ibm_db_conn = ibm_db.connect('MYDATABASE', '', '')

import ibm_db_dbi
conn = ibm_db_dbi.Connection(ibm_db_conn)
cursor = conn.cursor()

cursor.execute('SELECT 40.5 - 1 FROM SYSIBM.SYSDUMMY1')
print cursor.fetchone()

5. test-ibmdbsa.py is printing `(Decimal('39.5'),)` regardless of the locale.
6. echo "SELECT 40.5 - 1 FROM SYSIBM.SYSDUMMY1" | isql MYDATABASE
SQL> SELECT 40.5 - 1 FROM SYSIBM.SYSDUMMY1
+----------------+
| 1              |
+----------------+
| 39.5           |
+----------------+
SQLRowCount returns -1
1 rows fetched

So, only pyodbc is printing different values for different locales because of 
the decimal separator being `,` for de_DE.utf8, which is the locale of the 
client machine, but the database server uses `.` as the decimal separator. If I 
understood correctly, pyodbc currently determines the decimal separator from 
the client locale. Is it somehow possible for pyodbc to get the decimal 
separator settings from the database?

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

Debian Wheezy, pyodbc a0bab2c5

Original issue reported on code.google.com by friedric...@lsexperts.de on 4 Oct 2012 at 1:47