0
votes

I'm connecting to DB2-LUW database using Python 3.7 and some queries get error : "SQL0332N Character conversion from the source code page "1252" to the target code page "874" is not supported.***".

First I try to test the connection of Python to the database on DB2 by recreating a new table.

I insert 1 record and read it back. When I read the inserted row, I get the error.

Results in interactive python:

import ibm_db_dbi as dbi

print(dbi.__version__)
3.0.2

conn = dbi.connect("DATABASE=<db>;HOSTNAME=<hostname>;PORT=<port>;PROTOCOL=TCPIP;UID=<user>;PWD=<pwd>;", "", "")

c = conn.cursor()

c.execute('create table ibm_db_tst (col1 int)')
Out[5]: True

c.execute('insert into ibm_db_tst values(2)')
Out[6]: True

c.execute('select col1 from ibm_db_tst')
Out[7]: True

print(c.fetchone())

Traceback (most recent call last):

File "C:\Users\2400566\Anaconda3\lib\site-packages\ibm_db_dbi.py", line 1449, in _fetch_helper row = ibm_db.fetch_tuple(self.stmt_handler)

SQLCODE=-332lumn information cannot be retrieved: [IBM][CLI Driver][DB2/NT64] SQL0332N Character conversion from the source code page "1252" to the target code page "874" is not supported.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "", line 1, in print(c.fetchone())

File "C:\Users\2400566\Anaconda3\lib\site-packages\ibm_db_dbi.py", line 1475, in fetchone row_list = self._fetch_helper(1)

File "C:\Users\2400566\Anaconda3\lib\site-packages\ibm_db_dbi.py", line 1456, in _fetch_helper raise self.messages[len(self.messages) - 1]

SQLCODE=-332_dbi::Error: [IBM][CLI Driver][DB2/NT64] SQL0332N Character conversion from the source code page "1252" to the target code page "874" is not supported.

I'm not sure what's wrong? Need advice.

my Python version is Python 3.7.7 running on Window 10 PC x64

DB2 is on Windows server 2012 x64 .

DB2 version is DB2 v11.1.0.1527.

Database territory : GB Database code page : 1252 Database code set : 1252 Database country/region code : 44

Thanks in advance.

1
The problem is that your database has one code page and the environment another, that the driver does not understand how to convert between. 874 seems to be ISO 8859-11 which seems related to Thai. Is that deliberate? - Lennart
Please create (or alter) a system environment variable DB2CODEPAGE and set its value to 1208. You may need to reboot your windows workstation. Then retry the python script. You should also menion your python version and bitness, and the exact Windows edition and bitness. - mao
@Lennart , I'm not sure is it deliberate or not ? Need to confirm with IT person who help me set up this DB. - PreuttiP
@mao , my Python version is Python 3.7.7 running on Window 10 PC x64 and DB2 is on Windows server 2012 x64 and DB2 version is DB2 v11.1.0.1527. I'll try to change DB2CODEPAGE - PreuttiP
@mao I got more 1 question, why this problem happened only with Python? From the same window 10 Pc if connect to this DB2 I can create table insert update the table by using SQLworkbench/J. Any advise, why only Python is dependency. - PreuttiP

1 Answers

0
votes

In case that your python script is using db2dsdriver to connect to database on server, try to set the DisableUnicode keyword to 0 to enforce unicode code page (i.e. 1208) on Windows.

https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.swg.im.dbclient.config.doc/doc/r0054636.html