Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11487: pass long strings to Oracle as CLOB rather than NCLOB t…

…o prevent an encoding bug that occurs in some installations.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11285 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bbac0cc965ea90f31a365891d4e21b1bffa58f4a 1 parent 2d781aa
Ian Kelly authored July 21, 2009
6  django/db/backends/oracle/base.py
@@ -345,7 +345,7 @@ class OracleParam(object):
345 345
     """
346 346
     Wrapper object for formatting parameters for Oracle. If the string
347 347
     representation of the value is large enough (greater than 4000 characters)
348  
-    the input size needs to be set as NCLOB. Alternatively, if the parameter
  348
+    the input size needs to be set as CLOB. Alternatively, if the parameter
349 349
     has an `input_size` attribute, then the value of the `input_size` attribute
350 350
     will be used instead. Otherwise, no input size will be set for the
351 351
     parameter when executing the query.
@@ -360,8 +360,8 @@ def __init__(self, param, cursor, strings_only=False):
360 360
             # If parameter has `input_size` attribute, use that.
361 361
             self.input_size = param.input_size
362 362
         elif isinstance(param, basestring) and len(param) > 4000:
363  
-            # Mark any string param greater than 4000 characters as an NCLOB.
364  
-            self.input_size = Database.NCLOB
  363
+            # Mark any string param greater than 4000 characters as a CLOB.
  364
+            self.input_size = Database.CLOB
365 365
         else:
366 366
             self.input_size = None
367 367
 
15  tests/regressiontests/backends/tests.py
@@ -17,6 +17,21 @@ def test_dbms_session(self):
17 17
             return True
18 18
         else:
19 19
             return True
  20
+            
  21
+class LongString(unittest.TestCase):
  22
+
  23
+    def test_long_string(self):
  24
+        # If the backend is Oracle, test that we can save a text longer
  25
+        # than 4000 chars and read it properly
  26
+        if settings.DATABASE_ENGINE == 'oracle':
  27
+            c = connection.cursor()
  28
+            c.execute('CREATE TABLE ltext ("TEXT" NCLOB)')
  29
+            long_str = ''.join([unicode(x) for x in xrange(4000)])
  30
+            c.execute('INSERT INTO ltext VALUES (%s)',[long_str])
  31
+            c.execute('SELECT text FROM ltext')
  32
+            row = c.fetchone()
  33
+            c.execute('DROP TABLE ltext')
  34
+            self.assertEquals(long_str, row[0].read())
20 35
 
21 36
 def connection_created_test(sender, **kwargs):
22 37
     print 'connection_created signal'

0 notes on commit bbac0cc

Please sign in to comment.
Something went wrong with that request. Please try again.