Skip to content

Commit 77b269e

Browse files
Fixed django#11487: pass long strings to Oracle as CLOB rather than NCLOB to prevent an encoding bug that occurs in some installations. Backport of [11285] from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11286 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 72e2713 commit 77b269e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

django/db/backends/oracle/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class OracleParam(object):
319319
"""
320320
Wrapper object for formatting parameters for Oracle. If the string
321321
representation of the value is large enough (greater than 4000 characters)
322-
the input size needs to be set as NCLOB. Alternatively, if the parameter
322+
the input size needs to be set as CLOB. Alternatively, if the parameter
323323
has an `input_size` attribute, then the value of the `input_size` attribute
324324
will be used instead. Otherwise, no input size will be set for the
325325
parameter when executing the query.
@@ -331,8 +331,8 @@ def __init__(self, param, charset, strings_only=False):
331331
# If parameter has `input_size` attribute, use that.
332332
self.input_size = param.input_size
333333
elif isinstance(param, basestring) and len(param) > 4000:
334-
# Mark any string param greater than 4000 characters as an NCLOB.
335-
self.input_size = Database.NCLOB
334+
# Mark any string param greater than 4000 characters as a CLOB.
335+
self.input_size = Database.CLOB
336336
else:
337337
self.input_size = None
338338

tests/regressiontests/backends/tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@ def test_dbms_session(self):
2020
return True
2121
else:
2222
return True
23+
24+
class LongString(unittest.TestCase):
2325

26+
def test_long_string(self):
27+
# If the backend is Oracle, test that we can save a text longer
28+
# than 4000 chars and read it properly
29+
if settings.DATABASE_ENGINE == 'oracle':
30+
c = connection.cursor()
31+
c.execute('CREATE TABLE ltext ("TEXT" NCLOB)')
32+
long_str = ''.join([unicode(x) for x in xrange(4000)])
33+
c.execute('INSERT INTO ltext VALUES (%s)',[long_str])
34+
c.execute('SELECT text FROM ltext')
35+
row = c.fetchone()
36+
c.execute('DROP TABLE ltext')
37+
self.assertEquals(long_str, row[0].read())
2438

2539
if __name__ == '__main__':
2640
unittest.main()

0 commit comments

Comments
 (0)