Skip to content

Commit df102db

Browse files
Correct handling of CLOB/NCLOB when using different encodings.
1 parent d7f3854 commit df102db

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/LOB.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ static PyObject *LOB_InternalRead(udt_LOB *self, uint64_t offset,
188188
}
189189

190190
// return the result
191-
if (self->oracleTypeNum == DPI_ORACLE_TYPE_CLOB)
191+
if (self->oracleTypeNum == DPI_ORACLE_TYPE_NCLOB)
192192
result = PyUnicode_Decode(buffer, bufferSize,
193-
self->connection->encodingInfo.encoding, NULL);
194-
else if (self->oracleTypeNum == DPI_ORACLE_TYPE_NCLOB)
193+
self->connection->encodingInfo.nencoding, NULL);
194+
else if (self->oracleTypeNum == DPI_ORACLE_TYPE_CLOB)
195195
result = cxString_FromEncodedString(buffer, bufferSize,
196-
self->connection->encodingInfo.nencoding);
196+
self->connection->encodingInfo.encoding);
197197
else result = PyBytes_FromStringAndSize(buffer, bufferSize);
198198
PyMem_Free(buffer);
199199
return result;

test/LobVar.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ def testNCLOBsDirect(self):
169169
"test binding and fetching NCLOB data (directly)"
170170
self.__PerformTest("NCLOB", cx_Oracle.NCLOB)
171171

172+
def testNCLOBDifferentEncodings(self):
173+
"test binding and fetching NCLOB data (different encodings)"
174+
connection = cx_Oracle.connect(USERNAME, PASSWORD, TNSENTRY,
175+
encoding = "UTF-8", nencoding = "UTF-16")
176+
value = u"\u03b4\u4e2a"
177+
cursor = connection.cursor()
178+
cursor.execute("truncate table TestNCLOBs")
179+
cursor.execute("insert into TestNCLOBs values (1, :val)", val = value)
180+
cursor.execute("select NCLOBCol from TestNCLOBs")
181+
nclob, = cursor.fetchone()
182+
cursor.execute("update TestNCLOBs set NCLOBCol = :val",
183+
val = nclob.read() + value)
184+
cursor.execute("select NCLOBCol from TestNCLOBs")
185+
nclob, = cursor.fetchone()
186+
self.assertEqual(nclob.read(), value + value)
187+
172188
def testNCLOBsIndirect(self):
173189
"test binding and fetching NCLOB data (indirectly)"
174190
self.__PerformTest("NCLOB", cx_Oracle.LONG_STRING)

0 commit comments

Comments
 (0)