Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed Oracle failure for "%" in table name

  • Loading branch information...
1 parent 11699ac commit 2249bd275cbae6b73716bf36f5f36def1bb4222e @akaariai akaariai committed
4 django/db/backends/oracle/
@@ -256,6 +256,10 @@ def quote_name(self, name):
if not name.startswith('"') and not name.endswith('"'):
name = '"%s"' % util.truncate_name(name.upper(),
+ # 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):
8 tests/regressiontests/backends/
@@ -26,6 +26,14 @@
class OracleChecks(unittest.TestCase):
@unittest.skipUnless(connection.vendor == 'oracle',
+ "No need to check Oracle quote_name semantics")
@shaib Collaborator
shaib added a note

The comment is in contrast with the code -- the test is run only for Oracle.

@akaariai Collaborator

That is not comment - it is the reason why this test was skipped - we skipped this test because No need to check...

@shaib Collaborator
shaib added a note

Oh, I see. It is just a little ambiguous, IMO (there is a need to check Oracle quote_name semantics, but not when running on Postgres...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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
11 tests/regressiontests/inspectdb/
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
from import call_command
+from django.db import connection
from django.test import TestCase, skipUnlessDBFeature
from django.utils.six import StringIO
@@ -60,14 +61,16 @@ def test_digits_column_name_introspection(self):
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)

0 comments on commit 2249bd2

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