summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/connectors/pyodbc.py1
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py18
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py
index bc8a2f0b8..ef72c8049 100644
--- a/lib/sqlalchemy/connectors/pyodbc.py
+++ b/lib/sqlalchemy/connectors/pyodbc.py
@@ -142,6 +142,7 @@ class PyODBCConnector(Connector):
# run other initialization which asks for user name, etc.
super(PyODBCConnector, self).initialize(connection)
+
def _dbapi_version(self):
if not self.dbapi:
return ()
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index 547df8259..eebd35405 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -746,6 +746,12 @@ class MSExecutionContext(default.DefaultExecutionContext):
_result_proxy = None
_lastrowid = None
+ def _opt_encode(self, statement):
+ if not self.dialect.supports_unicode_statements:
+ return self.dialect._encoder(statement)[0]
+ else:
+ return statement
+
def pre_exec(self):
"""Activate IDENTITY_INSERT if needed."""
@@ -767,8 +773,8 @@ class MSExecutionContext(default.DefaultExecutionContext):
if self._enable_identity_insert:
self.root_connection._cursor_execute(self.cursor,
- "SET IDENTITY_INSERT %s ON" %
- self.dialect.identifier_preparer.format_table(tbl),
+ self._opt_encode("SET IDENTITY_INSERT %s ON" %
+ self.dialect.identifier_preparer.format_table(tbl)),
(), self)
def post_exec(self):
@@ -792,9 +798,9 @@ class MSExecutionContext(default.DefaultExecutionContext):
if self._enable_identity_insert:
conn._cursor_execute(self.cursor,
- "SET IDENTITY_INSERT %s OFF" %
+ self._opt_encode("SET IDENTITY_INSERT %s OFF" %
self.dialect.identifier_preparer.
- format_table(self.compiled.statement.table),
+ format_table(self.compiled.statement.table)),
(), self)
def get_lastrowid(self):
@@ -804,9 +810,9 @@ class MSExecutionContext(default.DefaultExecutionContext):
if self._enable_identity_insert:
try:
self.cursor.execute(
- "SET IDENTITY_INSERT %s OFF" %
+ self._opt_encode("SET IDENTITY_INSERT %s OFF" %
self.dialect.identifier_preparer.\
- format_table(self.compiled.statement.table)
+ format_table(self.compiled.statement.table))
)
except:
pass