diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-02 21:24:17 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-02 21:24:17 +0000 |
commit | 5bc1f17cb53248e7cea609693a3b2a9bb702545b (patch) | |
tree | e31a0341ecacd3115612fcebfc904f1549535465 /lib/sqlalchemy | |
parent | 2f2d84fbb14f1282677de8fc1186da8f41081214 (diff) | |
download | sqlalchemy-5bc1f17cb53248e7cea609693a3b2a9bb702545b.tar.gz |
- mysql, postgres: "%" signs in text() constructs are automatically escaped to "%%".
Because of the backwards incompatible nature of this change,
a warning is emitted if '%%' is detected in the string. [ticket:1267]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/databases/mysql.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 5 |
3 files changed, 14 insertions, 1 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 86fb7b247..1b977dce9 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -1952,6 +1952,11 @@ class MySQLCompiler(compiler.DefaultCompiler): return 'CAST(%s AS %s)' % (self.process(cast.clause), type_) + def post_process_text(self, text): + if '%%' in text: + util.warn("The SQLAlchemy MySQLDB dialect now automatically escapes '%' in text() expressions to '%%'.") + return text.replace('%', '%%') + def get_select_precolumns(self, select): if isinstance(select._distinct, basestring): return select._distinct.upper() + " " diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 273f5859e..6fd0662de 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -719,6 +719,11 @@ class PGCompiler(compiler.DefaultCompiler): else: return "nextval('%s')" % self.preparer.format_sequence(seq) + def post_process_text(self, text): + if '%%' in text: + util.warn("The SQLAlchemy psycopg2 dialect now automatically escapes '%' in text() expressions to '%%'.") + return text.replace('%', '%%') + def limit_clause(self, select): text = "" if select._limit is not None: diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 0430f053b..b286398bf 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -294,6 +294,9 @@ class DefaultCompiler(engine.Compiled): def visit_typeclause(self, typeclause, **kwargs): return typeclause.type.dialect_impl(self.dialect).get_col_spec() + def post_process_text(self, text): + return text + def visit_textclause(self, textclause, **kwargs): if textclause.typemap is not None: for colname, type_ in textclause.typemap.iteritems(): @@ -308,7 +311,7 @@ class DefaultCompiler(engine.Compiled): # un-escape any \:params return BIND_PARAMS_ESC.sub(lambda m: m.group(1), - BIND_PARAMS.sub(do_bindparam, textclause.text) + BIND_PARAMS.sub(do_bindparam, self.post_process_text(textclause.text)) ) def visit_null(self, null, **kwargs): |