From 2392ae1900f112c44ed966783d1dedfb88f13353 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 25 Aug 2017 15:26:02 -0400 Subject: Apply percent sign escaping to literal binds, comments Fixed bug in new percent-sign support (e.g. :ticket:`3740`) where a bound parameter rendered with literal_binds would fail to escape percent-signs for relevant dialects. In addition, ensured new table / column comment support feature also fully makes use of literal-rendered parameters so that this percent sign support takes place with table / column comment DDL as well, allowing percent sign support for the mysql / psycopg2 backends that require escaping of percent signs. Change-Id: Ia4136a300933e9bc6a01a7b9afd5c7b9a3fee4e3 Fixes: #4054 Fixes: #4052 --- lib/sqlalchemy/sql/sqltypes.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 6838baa5f..fe9a56b6e 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -205,6 +205,10 @@ class String(Concatenable, TypeEngine): def literal_processor(self, dialect): def process(value): value = value.replace("'", "''") + + if dialect.identifier_preparer._double_percents: + value = value.replace('%', '%%') + return "'%s'" % value return process -- cgit v1.2.1