Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed ORA-01461 error when trying to store more than 4000 bytes in a …

…TextField under Oracle

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6905 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ed5eca598e6e0fced2262dafa052d5db1661d83a 1 parent f425cb8
@ikelly ikelly authored
View
19 django/db/backends/oracle/base.py
@@ -455,6 +455,23 @@ def _format_params(self, params):
else:
return tuple([smart_str(p, self.charset, True) for p in params])
+ def _guess_input_sizes(self, params_list):
+ # Mark any string parameter greater than 4000 characters as an NCLOB.
+ if isinstance(params_list[0], dict):
+ sizes = {}
+ iterators = [params.iteritems() for params in params_list]
+ else:
+ sizes = [None] * len(params_list[0])
+ iterators = [enumerate(params) for params in params_list]
+ for iterator in iterators:
+ for key, value in iterator:
+ if isinstance(value, basestring) and len(value) > 4000:
+ sizes[key] = Database.NCLOB
+ if isinstance(sizes, dict):
+ self.setinputsizes(**sizes)
+ else:
+ self.setinputsizes(*sizes)
+
def execute(self, query, params=None):
if params is None:
params = []
@@ -468,6 +485,7 @@ def execute(self, query, params=None):
if query.endswith(';') or query.endswith('/'):
query = query[:-1]
query = smart_str(query, self.charset) % tuple(args)
+ self._guess_input_sizes([params])
return Database.Cursor.execute(self, query, params)
def executemany(self, query, params=None):
@@ -484,6 +502,7 @@ def executemany(self, query, params=None):
query = query[:-1]
query = smart_str(query, self.charset) % tuple(args)
new_param_list = [self._format_params(i) for i in params]
+ self._guess_input_sizes(new_param_list)
return Database.Cursor.executemany(self, query, new_param_list)
def fetchone(self):
View
10 tests/regressiontests/model_regress/models.py
@@ -11,6 +11,7 @@ class Article(models.Model):
pub_date = models.DateTimeField()
status = models.IntegerField(blank=True, null=True, choices=CHOICES)
misc_data = models.CharField(max_length=100, blank=True)
+ article_text = models.TextField()
class Meta:
ordering = ('pub_date','headline')
@@ -41,5 +42,14 @@ class Movie(models.Model):
>>> a2 = Article.objects.get(pk=a.id)
>>> a2.misc_data
u''
+
+# TextFields can hold more than 4000 characters (this was broken in Oracle).
+>>> a3 = Article(headline="Really, really big", pub_date=datetime.now())
+>>> a3.article_text = "ABCDE" * 1000
+>>> a3.save()
+>>> a4 = Article.objects.get(pk=a3.id)
+>>> len(a4.article_text)
+5000
+
"""
}
Please sign in to comment.
Something went wrong with that request. Please try again.