]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add preparer to pymssql that disables percent doubling
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Aug 2017 16:19:54 +0000 (12:19 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Aug 2017 16:27:21 +0000 (12:27 -0400)
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
doc/build/changelog/unreleased_12/4057.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mssql/pymssql.py

diff --git a/doc/build/changelog/unreleased_12/4057.rst b/doc/build/changelog/unreleased_12/4057.rst
new file mode 100644 (file)
index 0000000..e641485
--- /dev/null
@@ -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.
index cd800471d46e98c9bb37d7998500cceda7b344de..51237990e90dc581a283f55067168ab80e8f8c5b 100644 (file)
@@ -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,
         {