]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed the "render literal bind" function,
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 13 Feb 2012 23:53:21 +0000 (18:53 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 13 Feb 2012 23:53:21 +0000 (18:53 -0500)
used by Alembic, to escape % signs with %%.

CHANGES
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/test_postgresql.py

diff --git a/CHANGES b/CHANGES
index 29e8c2ba0f91b3ef3c434178353477b655b86115..b589751eb2f6a0d33b07eaee27c4fef9e579e9ba 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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
index c4c2bbdb4e56cae4faf033978197ee278aa28f08..51f69b7b2cdb0c0431410441ac270b9a10309b6d 100644 (file)
@@ -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):
index 769f18ce9a6d0c2cfefb8ce4bb80ccc7a3b0cf19..a537ee3e9e63087b200a4214f50bf460c451f22b 100644 (file)
@@ -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()