google-code-export / ibm-db

Automatically exported from code.google.com/p/ibm-db
1 stars 0 forks source link

Failed to insert/update Greek data with Python #128

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Cannot insert/update character columns with Greek data with python. The 
application code page is 1253 and the connection codepage is 1208. How can I 
change the connection code page? (there is nothing relevant in ibm_db docs)  

I am using:
OpSys: Win 7 sp1
DB2  : 10.2 (Connect personal 32 bit)
Python: 2.7.4 (32 bit)
ibm_db: 2.0.2   

I connect with the following statement: 
con=ibm_db.connect("DRIVER={IBM DB2 ODBC 
DRIVER};DATABASE=.;HOSTNAME=.;PORT=.;PROTOCOL=TCPIP;UID=.;PWD=.;", "", "")

Original issue reported on code.google.com by zisisk...@gmail.com on 2 May 2013 at 3:40

GoogleCodeExporter commented 9 years ago
What do you mean by connection codepage here, and what the error message you 
gets during insert/update of data 

Original comment by rahul.pr...@in.ibm.com on 3 May 2013 at 6:54

GoogleCodeExporter commented 9 years ago
when the python program starts I print the
 ibm_db.client_info().CONN_CODEPAGE (1208) and APPL_CODEPAGE attributes
(1253). I do not get any error message during insert/update, but the data
inserted/updated are invalid. when i run a select query for the relevant
columns to see what has been placed in there, I see something like this
'Νικος Ζ Κατσαρο�' . I want to point out that I only have this
problem with ibm_db/python. Everything else works fine (that is : python
with pyodbc , java , c/c++, microfocus cobol)

Original comment by zisisk...@gmail.com on 3 May 2013 at 7:31

GoogleCodeExporter commented 9 years ago
could you please share the sample test script to reproduce this issue.

Original comment by rahul.pr...@in.ibm.com on 3 May 2013 at 9:29

GoogleCodeExporter commented 9 years ago
I have tried with u'Ομάδ' greek word but it get inserted and retrieved 
correctly.  

Original comment by rahul.pr...@in.ibm.com on 3 May 2013 at 9:35

GoogleCodeExporter commented 9 years ago
The Connection codepage you are getting is not changeable through any setting, 
It depends on your Database codepage and Application codepage. 

Original comment by rahul.pr...@in.ibm.com on 3 May 2013 at 9:39

GoogleCodeExporter commented 9 years ago
# coding:iso-8859-7
from ibm_db import *
con=connect("DRIVER={IBM DB2 ODBC DRIVER};"+
    "DATABASE=DB2LT;HOSTNAME=10.2.7.116;PORT=50001;PROTOCOL=TCPIP;"
    "UID=DB2TEST;PWD=db2test;","","")

ci=client_info(con)
print 'APPL_CODEPAGE=',ci.APPL_CODEPAGE,'CONN_CODEPAGE=',ci.CONN_CODEPAGE

s=exec_immediate(con,"update kats.ttab1 set vdat='����� � ��������'")
n=num_rows(s)
print 'Number of rows Updated=', n

stmt = exec_immediate(con,"select vdat from kats.ttab1")
r = fetch_tuple(stmt)
while r:
    print r[0]
    r = fetch_tuple(stmt)

--------------------------------------------------------------------------------
-----
This is the output from the above script

APPL_CODEPAGE= 1253 CONN_CODEPAGE= 1208
Number of rows Updated= 6
Νικος Ζ Κατσαρος
Νικος Ζ Κατσαρος
Νικος Ζ Κατσαρος
Νικος Ζ Κατσαρος
Νικος Ζ Κατσαρος
Νικος Ζ Κατσαρος

Original comment by zisisk...@gmail.com on 3 May 2013 at 9:41

GoogleCodeExporter commented 9 years ago
This problem is due to Literal Replacement Feature of CLI which is ON in 
default. Please tern it OFF by passing QUOTED_LITERAL_REPLACEMENT_OFF 
environment variable in connect() function

eg: ibm_db.connect(database_name, user_name, password, {}, 
ibm_db.QUOTED_LITERAL_REPLACEMENT_OFF)

From the next release we are thinking of to disable the Literal Replacement 
Feature in default.

This problem can also be get resolved by passing the data through parameter 
marker.

eg s = ibm_db.prepare(con, "update kats.ttab1 set vdat= ?")
   ibm_db.execute(s, (u'����� � ��������', ))

Original comment by rahul.pr...@in.ibm.com on 3 May 2013 at 10:03

GoogleCodeExporter commented 9 years ago
did you try u'����' inside a python program with imb_db ? (because as I
told you everything else works fine) in any case I have also tried the
following: s=exec_immediate(con,u"update kats.ttab1 set vdat='����� �
��������'")
s=exec_immediate(con,"update kats.ttab1 set vdat='"+u'����� �
��������'+"'") and I had the same results.

2013/5/3 Zisis Katsaros <zisiskats@gmail.com>

Original comment by zisisk...@gmail.com on 3 May 2013 at 10:04

GoogleCodeExporter commented 9 years ago
OK !!!! problem solved ... many thanks (and have a nice weekend)

2013/5/3 Zisis Katsaros <zisiskats@gmail.com>

Original comment by zisisk...@gmail.com on 3 May 2013 at 10:09

GoogleCodeExporter commented 9 years ago

Original comment by rahul.pr...@in.ibm.com on 3 May 2013 at 10:12