From: Mike Bayer Date: Wed, 30 Aug 2017 16:19:54 +0000 (-0400) Subject: Add preparer to pymssql that disables percent doubling X-Git-Tag: origin~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51c24329181f8bef17348f9b3899303569d32c81;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add preparer to pymssql that disables percent doubling Fixed the pymssql dialect so that percent signs in SQL text, such as used in modulus expressions or literal textual values, are **not** doubled up, as seems to be what pymssql expects. This is despite the fact that the pymssql DBAPI uses the "pyformat" parameter style which itself considers the percent sign to be significant. Tests are part of standard suite already (CI has been disabled) Change-Id: Ie05de403caefcba3292a967183a995e95a5854d5 Fixes: #4057 --- diff --git a/doc/build/changelog/unreleased_12/4057.rst b/doc/build/changelog/unreleased_12/4057.rst new file mode 100644 index 0000000000..e64148518b --- /dev/null +++ b/doc/build/changelog/unreleased_12/4057.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: mssql, bug + :tickets: 4057 + + Fixed the pymssql dialect so that percent signs in SQL text, such + as used in modulus expressions or literal textual values, are + **not** doubled up, as seems to be what pymssql expects. This is + despite the fact that the pymssql DBAPI uses the "pyformat" parameter + style which itself considers the percent sign to be significant. diff --git a/lib/sqlalchemy/dialects/mssql/pymssql.py b/lib/sqlalchemy/dialects/mssql/pymssql.py index cd800471d4..51237990e9 100644 --- a/lib/sqlalchemy/dialects/mssql/pymssql.py +++ b/lib/sqlalchemy/dialects/mssql/pymssql.py @@ -18,7 +18,7 @@ pymssql is a Python module that provides a Python DBAPI interface around Linux, MacOSX and Windows platforms. """ -from .base import MSDialect +from .base import MSDialect, MSIdentifierPreparer from ... import types as sqltypes, util, processors import re @@ -31,10 +31,21 @@ class _MSNumeric_pymssql(sqltypes.Numeric): return sqltypes.Numeric.result_processor(self, dialect, type_) +class MSIdentifierPreparer_pymssql(MSIdentifierPreparer): + + def __init__(self, dialect): + super(MSIdentifierPreparer_pymssql, self).__init__(dialect) + # pymssql has the very unusual behavior that it uses pyformat + # yet does not require that percent signs be doubled + self._double_percents = False + + class MSDialect_pymssql(MSDialect): supports_sane_rowcount = False driver = 'pymssql' + preparer = MSIdentifierPreparer_pymssql + colspecs = util.update_copy( MSDialect.colspecs, {