summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-08-30 12:19:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-08-30 12:27:21 -0400
commit51c24329181f8bef17348f9b3899303569d32c81 (patch)
tree193936c051ba2e11231ac4324157bb5a4de2f50e
parent812c08efb41ff0a8bdafb876fe49079da5074916 (diff)
downloadsqlalchemy-51c24329181f8bef17348f9b3899303569d32c81.tar.gz
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
-rw-r--r--doc/build/changelog/unreleased_12/4057.rst9
-rw-r--r--lib/sqlalchemy/dialects/mssql/pymssql.py13
2 files changed, 21 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_12/4057.rst b/doc/build/changelog/unreleased_12/4057.rst
new file mode 100644
index 000000000..e64148518
--- /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 cd800471d..51237990e 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,
{