summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-07-14 19:02:20 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-07-14 19:02:20 -0400
commit2825730e7be6e18aac32bcef4f6eeb0a5acab2a0 (patch)
tree73105fceb88f212c5d350fc8a07be636bfa2edc3 /lib/sqlalchemy
parent0add251ea0be13a54c410f3c6e145e52482fb31d (diff)
downloadsqlalchemy-2825730e7be6e18aac32bcef4f6eeb0a5acab2a0.tar.gz
- Added statement encoding to the "SET IDENTITY_INSERT"
statements which operate when an explicit INSERT is being interjected into an IDENTITY column, to support non-ascii table identifiers on drivers such as pyodbc + unix + py2k that don't support unicode statements. ref #3091 as this fix is also in that issue's patch, but is a different issue.
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