.. changelog::
:version: 0.8.7
+ .. change::
+ :tags: bug, mssql
+ :versions: 1.0.0, 0.9.7
+
+ 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.
+
.. change::
:tags: bug, mssql
:versions: 1.0.0, 0.9.7
_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."""
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):
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):
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