From f0d2e599b60317fc27f64f0abe7d2af65fba7e7b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 9 Aug 2009 22:11:40 +0000 Subject: - PG: somewhat better support for % signs in table/column names; psycopg2 can't handle a bind parameter name of %(foobar)s however and SQLA doesn't want to add overhead just to treat that one non-existent use case. [ticket:1279] - MySQL: somewhat better support for % signs in table/column names; MySQLdb can't handle % signs in SQL when executemany() is used, and SQLA doesn't want to add overhead just to treat that one non-existent use case. [ticket:1279] --- lib/sqlalchemy/dialects/mysql/base.py | 7 ++++++- lib/sqlalchemy/dialects/postgresql/base.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 1c5c251e5..570d1a79b 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -2514,6 +2514,10 @@ class _MySQLIdentifierPreparer(compiler.IdentifierPreparer): return tuple([self.quote_identifier(i) for i in ids if i is not None]) + def _escape_identifier(self, value): + value = value.replace('"', '""') + return value.replace('%', '%%') + class MySQLIdentifierPreparer(_MySQLIdentifierPreparer): """Traditional MySQL-specific schema identifier configuration.""" @@ -2522,7 +2526,8 @@ class MySQLIdentifierPreparer(_MySQLIdentifierPreparer): super(MySQLIdentifierPreparer, self).__init__(dialect, initial_quote="`") def _escape_identifier(self, value): - return value.replace('`', '``') + value = value.replace('`', '``') + return value.replace('%', '%%') def _unescape_identifier(self, value): return value.replace('``', '`') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index fbba8221b..c89ae16bd 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -431,6 +431,10 @@ class PGIdentifierPreparer(compiler.IdentifierPreparer): value = value[1:-1].replace('""','"') return value + def _escape_identifier(self, value): + value = value.replace('"', '""') + return value.replace('%', '%%') + class PGInspector(reflection.Inspector): def __init__(self, conn): -- cgit v1.2.1