summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-10-27 04:51:14 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2012-10-27 05:26:42 +0300
commit2249bd275cbae6b73716bf36f5f36def1bb4222e (patch)
treead7cbdbfefc680c2dcf9fa1641cfbae5f3351ffc
parent11699ac4b5f98ec11dba02b356a8fd4ab6b4b889 (diff)
Fixed Oracle failure for "%" in table name
-rw-r--r--django/db/backends/oracle/base.py4
-rw-r--r--tests/regressiontests/backends/tests.py8
-rw-r--r--tests/regressiontests/inspectdb/tests.py11
3 files changed, 19 insertions, 4 deletions
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 6bf2e815a7..aad52992dd 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -256,6 +256,10 @@ WHEN (new.%(col_name)s IS NULL)
if not name.startswith('"') and not name.endswith('"'):
name = '"%s"' % util.truncate_name(name.upper(),
self.max_name_length())
+ # Oracle puts the query text into a (query % args) construct, so % signs
+ # in names need to be escaped. The '%%' will be collapsed back to '%' at
+ # that stage so we aren't really making the name longer here.
+ name = name.replace('%','%%')
return name.upper()
def random_function_sql(self):
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index d284cfaac8..4766dcf44e 100644
--- a/tests/regressiontests/backends/tests.py
+++ b/tests/regressiontests/backends/tests.py
@@ -26,6 +26,14 @@ from . import models
class OracleChecks(unittest.TestCase):
@unittest.skipUnless(connection.vendor == 'oracle',
+ "No need to check Oracle quote_name semantics")
+ def test_quote_name(self):
+ # Check that '%' chars are escaped for query execution.
+ name = '"SOME%NAME"'
+ quoted_name = connection.ops.quote_name(name)
+ self.assertEquals(quoted_name % (), name)
+
+ @unittest.skipUnless(connection.vendor == 'oracle',
"No need to check Oracle cursor semantics")
def test_dbms_session(self):
# If the backend is Oracle, test that we can call a standard
diff --git a/tests/regressiontests/inspectdb/tests.py b/tests/regressiontests/inspectdb/tests.py
index 484e7f4060..028d263337 100644
--- a/tests/regressiontests/inspectdb/tests.py
+++ b/tests/regressiontests/inspectdb/tests.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
from django.core.management import call_command
+from django.db import connection
from django.test import TestCase, skipUnlessDBFeature
from django.utils.six import StringIO
@@ -60,14 +61,16 @@ class InspectDBTestCase(TestCase):
self.assertIn("number_45extra = models.CharField", output)
def test_special_column_name_introspection(self):
- """Introspection of column names containing special characters,
- unsuitable for Python identifiers
+ """
+ Introspection of column names containing special characters,
+ unsuitable for Python identifiers
"""
out = StringIO()
call_command('inspectdb', stdout=out)
output = out.getvalue()
+ base_name = 'Field' if connection.vendor != 'oracle' else 'field'
self.assertIn("field = models.IntegerField()", output)
- self.assertIn("field_field = models.IntegerField(db_column='Field_')", output)
- self.assertIn("field_field_0 = models.IntegerField(db_column='Field__')", output)
+ self.assertIn("field_field = models.IntegerField(db_column='%s_')" % base_name, output)
+ self.assertIn("field_field_0 = models.IntegerField(db_column='%s__')" % base_name, output)
self.assertIn("field_field_1 = models.IntegerField(db_column='__field')", output)
self.assertIn("prc_x = models.IntegerField(db_column='prc(%) x')", output)