pymssql percent signs need to not be doubled

Issue #4057 resolved
Mike Bayer repo owner created an issue
from sqlalchemy import *

e = create_engine("mssql+pymssql://scott:tiger^5HHH@mssql2017:1433/test", echo=True)

c = e.connect()
c.execute("drop table if exists foo")
c.execute("""
    create table foo (
        d1 integer,
        d2 integer
    )
""")

c.execute(text("""
    insert into foo (d1, d2) values (:d1, 29 % 10)
"""), {"d1": 10})

print c.execute("select * from foo").fetchall()
sqlalchemy.exc.ProgrammingError: (pymssql.ProgrammingError) (102, "Incorrect syntax near '10'.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n") [SQL: '\n    insert into foo (d1, d2) values (%(d1)s, 29 %% 10)\n'] [parameters: {'d1': 10}]

Comments (1)

  1. Mike Bayer reporter

    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

    → <<cset 51c24329181f>>

  2. Log in to comment