summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-01-09 22:17:59 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-01-12 13:01:26 -0500
commit7402987fd218c42ed2a909a5031186d2b702bb88 (patch)
treea418897eb557bbdad09878aa7dcc2e2aab7dfb3a /lib/sqlalchemy/sql/compiler.py
parent127ead7452f326509cde38fcf7c9f38f69d9ae0a (diff)
downloadsqlalchemy-7402987fd218c42ed2a909a5031186d2b702bb88.tar.gz
Make column-level collation quoting dialect-specific
Fixed regression in 1.2 where newly repaired quoting of collation names in :ticket:`3785` breaks SQL Server, which explicitly does not understand a quoted collation name. Whether or not mixed-case collation names are quoted or not is now deferred down to a dialect-level decision so that each dialect can prepare these identifiers directly. Change-Id: Iaf0a8123d9bf4711219e320896bb28c5d2649304 Fixes: #4154
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index cb058affa..9411329a1 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -733,6 +733,9 @@ class SQLCompiler(Compiled):
self.preparer.quote(tablename) + \
"." + name
+ def visit_collation(self, element, **kw):
+ return self.preparer.format_collation(element.collation)
+
def visit_fromclause(self, fromclause, **kwargs):
return fromclause.name
@@ -2961,7 +2964,8 @@ class IdentifierPreparer(object):
schema_for_object = schema._schema_getter(None)
def __init__(self, dialect, initial_quote='"',
- final_quote=None, escape_quote='"', omit_schema=False):
+ final_quote=None, escape_quote='"',
+ quote_case_sensitive_collations=True, omit_schema=False):
"""Construct a new ``IdentifierPreparer`` object.
initial_quote
@@ -2982,6 +2986,7 @@ class IdentifierPreparer(object):
self.escape_quote = escape_quote
self.escape_to_quote = self.escape_quote * 2
self.omit_schema = omit_schema
+ self.quote_case_sensitive_collations = quote_case_sensitive_collations
self._strings = {}
self._double_percents = self.dialect.paramstyle in ('format', 'pyformat')
@@ -3064,6 +3069,12 @@ class IdentifierPreparer(object):
else:
return ident
+ def format_collation(self, collation_name):
+ if self.quote_case_sensitive_collations:
+ return self.quote(collation_name)
+ else:
+ return collation_name
+
def format_sequence(self, sequence, use_schema=True):
name = self.quote(sequence.name)