diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-02-13 18:53:21 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-02-13 18:53:21 -0500 |
| commit | 4bbd814fffb563e38f776d7c11ab162f8095ca51 (patch) | |
| tree | 02aee0327473b057b16af95fac8440a4ba56c86a | |
| parent | 1aeb637e70e4f9f098ab8b4c4462975b805e9965 (diff) | |
| download | sqlalchemy-4bbd814fffb563e38f776d7c11ab162f8095ca51.tar.gz | |
- [bug] Fixed the "render literal bind" function,
used by Alembic, to escape % signs with %%.
| -rw-r--r-- | CHANGES | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 1 | ||||
| -rw-r--r-- | test/dialect/test_postgresql.py | 12 |
3 files changed, 17 insertions, 0 deletions
@@ -93,6 +93,10 @@ CHANGES commit or rollback transaction with errors on engine.begin(). +- postgresql + - [bug] Fixed the "render literal bind" function, + used by Alembic, to escape % signs with %%. + - mysql - [feature] Added support for the "isolation_level" parameter to all MySQL dialects. Thanks diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index c4c2bbdb4..51f69b7b2 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -644,6 +644,7 @@ class PGCompiler(compiler.SQLCompiler): # TODO: need to inspect "standard_conforming_strings" if self.dialect._backslash_escapes: value = value.replace('\\', '\\\\') + value = value.replace("%", "%%") return value def visit_sequence(self, seq): diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 769f18ce9..a537ee3e9 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -74,6 +74,18 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): 'RETURNING length(mytable.name) AS length_1' , dialect=dialect) + def test_render_literal(self): + dialect = postgresql.dialect() + compiler = dialect.statement_compiler(dialect, None) + for value, exp in [ + ('hi', "'hi'"), + ("with 'quotes'", "'with ''quotes'''"), + ('%.%', "'%%.%%'") + ]: + eq_( + compiler.render_literal_value(value, None), + exp + ) def test_insert_returning(self): dialect = postgresql.dialect() |
