From 86ef507cc73ee4a0a104b334d7ce08ad045e0c76 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 4 Jul 2016 15:54:29 -0400 Subject: Double percent signs based on paramstyle, not dialect This patch moves the "doubling" of percent signs into the base compiler and makes it completely a product of whether or not the paramstyle is format/pyformat or not. Without this paramstyle, percent signs are not doubled across text(), literal_column(), and column(). Change-Id: Ie2f278ab1dbb94b5078f85c0096d74dbfa049197 Fixes: #3740 --- lib/sqlalchemy/testing/suite/test_dialect.py | 34 +++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/suite/test_dialect.py b/lib/sqlalchemy/testing/suite/test_dialect.py index 00884a212..0e62c347f 100644 --- a/lib/sqlalchemy/testing/suite/test_dialect.py +++ b/lib/sqlalchemy/testing/suite/test_dialect.py @@ -1,9 +1,11 @@ from .. import fixtures, config from ..config import requirements from sqlalchemy import exc -from sqlalchemy import Integer, String +from sqlalchemy import Integer, String, select, literal_column from .. import assert_raises from ..schema import Table, Column +from .. import provide_metadata +from .. import eq_ class ExceptionTest(fixtures.TablesTest): @@ -39,3 +41,33 @@ class ExceptionTest(fixtures.TablesTest): self.tables.manual_pk.insert(), {'id': 1, 'data': 'd1'} ) + + +class EscapingTest(fixtures.TestBase): + @provide_metadata + def test_percent_sign_round_trip(self): + """test that the DBAPI accommodates for escaped / nonescaped + percent signs in a way that matches the compiler + + """ + m = self.metadata + t = Table('t', m, Column('data', String(50))) + t.create(config.db) + with config.db.begin() as conn: + conn.execute(t.insert(), dict(data="some % value")) + conn.execute(t.insert(), dict(data="some %% other value")) + + eq_( + conn.scalar( + select([t.c.data]).where( + t.c.data == literal_column("'some % value'")) + ), + "some % value" + ) + + eq_( + conn.scalar( + select([t.c.data]).where( + t.c.data == literal_column("'some %% other value'")) + ), "some %% other value" + ) -- cgit v1.2.1