From 05a693fcb7a57f0362e06da1517cb35279bfaad1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 11 Jan 2008 21:30:02 +0000 Subject: [PATCH] fixed NOT ILIKE --- lib/sqlalchemy/databases/postgres.py | 3 ++- lib/sqlalchemy/sql/compiler.py | 2 +- test/sql/select.py | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index bab998d697..220c2a487a 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -626,7 +626,8 @@ class PGCompiler(compiler.DefaultCompiler): operators.update( { sql_operators.mod : '%%', - sql_operators.ilike_op: 'ILIKE' + sql_operators.ilike_op: 'ILIKE', + sql_operators.notilike_op: 'NOT ILIKE' } ) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 545c0a1b42..8f2e3372a3 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -80,7 +80,7 @@ OPERATORS = { operators.like_op : 'LIKE', operators.notlike_op : 'NOT LIKE', operators.ilike_op : lambda x, y: "lower(%s) LIKE lower(%s)" % (x, y), - operators.notilike_op : 'NOT ILIKE', + operators.notilike_op : lambda x, y: "lower(%s) NOT LIKE lower(%s)" % (x, y), operators.between_op : 'BETWEEN', operators.in_op : 'IN', operators.notin_op : 'NOT IN', diff --git a/test/sql/select.py b/test/sql/select.py index b922c5c22c..4c15bfb1b8 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -527,9 +527,13 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A def testilike(self): stmt = table1.select(table1.c.name.ilike('%something%')) - self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE lower(mytable.name) LIKE :mytable_name_1") + self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE lower(mytable.name) LIKE lower(:mytable_name_1)") self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.name ILIKE %(mytable_name_1)s", dialect=postgres.PGDialect()) + stmt = table1.select(~table1.c.name.ilike('%something%')) + self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE lower(mytable.name) NOT LIKE lower(:mytable_name_1)") + self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.name NOT ILIKE %(mytable_name_1)s", dialect=postgres.PGDialect()) + def testforupdate(self): self.assert_compile(table1.select(table1.c.myid==7, for_update=True), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid = :mytable_myid_1 FOR UPDATE") -- 2.47.3