summaryrefslogtreecommitdiff
path: root/django/db/backends
diff options
context:
space:
mode:
authorAndrew Nester <andrew.nester.dev@gmail.com>2016-12-31 01:11:12 +0300
committerTim Graham <timograham@gmail.com>2016-12-30 17:11:12 -0500
commit69b7d4b116e3b70b250c77829e11038d5d55c2a8 (patch)
tree71b093eb6a2391de013e8cb82b7ce06d6298949a /django/db/backends
parent398a859642636a2de0ab920befa320cd9954b49a (diff)
Fixed #27458 -- Fixed invalid sequence/index names when using "USER"."TABLE" db_table on Oracle.
Diffstat (limited to 'django/db/backends')
-rw-r--r--django/db/backends/base/schema.py3
-rw-r--r--django/db/backends/oracle/operations.py8
-rw-r--r--django/db/backends/utils.py10
3 files changed, 17 insertions, 4 deletions
diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py
index 3db3c76b7b..b00853b74d 100644
--- a/django/db/backends/base/schema.py
+++ b/django/db/backends/base/schema.py
@@ -2,6 +2,7 @@ import hashlib
import logging
from datetime import datetime
+from django.db.backends.utils import strip_quotes
from django.db.transaction import TransactionManagementError, atomic
from django.utils import six, timezone
from django.utils.encoding import force_bytes
@@ -841,7 +842,7 @@ class BaseDatabaseSchemaEditor(object):
The name is divided into 3 parts: the table name, the column names,
and a unique digest and suffix.
"""
- table_name = model._meta.db_table
+ table_name = strip_quotes(model._meta.db_table)
hash_data = [table_name] + list(column_names)
hash_suffix_part = '%s%s' % (self._digest(*hash_data), suffix)
max_length = self.connection.ops.max_name_length() or 200
diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py
index d55c003383..e283c574f2 100644
--- a/django/db/backends/oracle/operations.py
+++ b/django/db/backends/oracle/operations.py
@@ -6,7 +6,7 @@ import uuid
from django.conf import settings
from django.db.backends.base.operations import BaseDatabaseOperations
-from django.db.backends.utils import truncate_name
+from django.db.backends.utils import strip_quotes, truncate_name
from django.utils import six, timezone
from django.utils.encoding import force_bytes, force_text
@@ -450,11 +450,13 @@ WHEN (new.%(col_name)s IS NULL)
def _get_sequence_name(self, table):
name_length = self.max_name_length() - 3
- return '%s_SQ' % truncate_name(table, name_length).upper()
+ sequence_name = '%s_SQ' % strip_quotes(table)
+ return truncate_name(sequence_name, name_length).upper()
def _get_trigger_name(self, table):
name_length = self.max_name_length() - 3
- return '%s_TR' % truncate_name(table, name_length).upper()
+ trigger_name = '%s_TR' % strip_quotes(table)
+ return truncate_name(trigger_name, name_length).upper()
def bulk_insert_sql(self, fields, placeholder_rows):
return " UNION ALL ".join(
diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py
index c01bcc2598..73f1dbb690 100644
--- a/django/db/backends/utils.py
+++ b/django/db/backends/utils.py
@@ -209,3 +209,13 @@ def format_number(value, max_digits, decimal_places):
if decimal_places is not None:
return "%.*f" % (decimal_places, value)
return "{:f}".format(value)
+
+
+def strip_quotes(table_name):
+ """
+ Strip quotes off of quoted table names to make them safe for use in index
+ names, sequence names, etc. For example '"USER"."TABLE"' (an Oracle naming
+ scheme) becomes 'USER"."TABLE'.
+ """
+ has_quotes = table_name.startswith('"') and table_name.endswith('"')
+ return table_name[1:-1] if has_quotes else table_name