|
18 | 18 | # However, if you have executed another commercial license agreement
|
19 | 19 | # with Crate these terms will supersede the license and you may use the
|
20 | 20 | # software solely pursuant to the terms of the relevant commercial agreement.
|
21 |
| - |
| 21 | +from textwrap import dedent |
22 | 22 | from unittest import mock, TestCase, skipIf
|
23 | 23 |
|
24 | 24 | from crate.client.sqlalchemy.compiler import crate_before_execute
|
@@ -71,6 +71,58 @@ def test_bulk_update_on_builtin_type(self):
|
71 | 71 |
|
72 | 72 | self.assertFalse(hasattr(clauseelement, '_crate_specific'))
|
73 | 73 |
|
| 74 | + def test_select_with_ilike(self): |
| 75 | + """ |
| 76 | + Verify the compiler uses CrateDB's native `ILIKE` method. |
| 77 | + """ |
| 78 | + selectable = self.mytable.select().where(self.mytable.c.name.ilike("%foo%")) |
| 79 | + statement = str(selectable.compile(bind=self.crate_engine)) |
| 80 | + self.assertEqual(statement, dedent(""" |
| 81 | + SELECT mytable.name, mytable.data |
| 82 | + FROM mytable |
| 83 | + WHERE mytable.name ILIKE ? |
| 84 | + """).strip()) # noqa: W291 |
| 85 | + |
| 86 | + def test_select_with_not_ilike(self): |
| 87 | + """ |
| 88 | + Verify the compiler uses CrateDB's native `ILIKE` method. |
| 89 | + """ |
| 90 | + selectable = self.mytable.select().where(self.mytable.c.name.notilike("%foo%")) |
| 91 | + statement = str(selectable.compile(bind=self.crate_engine)) |
| 92 | + if SA_VERSION < SA_1_4: |
| 93 | + self.assertEqual(statement, dedent(""" |
| 94 | + SELECT mytable.name, mytable.data |
| 95 | + FROM mytable |
| 96 | + WHERE lower(mytable.name) NOT LIKE lower(?) |
| 97 | + """).strip()) # noqa: W291 |
| 98 | + else: |
| 99 | + self.assertEqual(statement, dedent(""" |
| 100 | + SELECT mytable.name, mytable.data |
| 101 | + FROM mytable |
| 102 | + WHERE mytable.name NOT ILIKE ? |
| 103 | + """).strip()) # noqa: W291 |
| 104 | + |
| 105 | + def test_select_with_ilike_and_escape(self): |
| 106 | + """ |
| 107 | + Verify the compiler fails when using CrateDB's native `ILIKE` method together with `ESCAPE`. |
| 108 | + """ |
| 109 | + |
| 110 | + selectable = self.mytable.select().where(self.mytable.c.name.ilike("%foo%", escape='\\')) |
| 111 | + with self.assertRaises(NotImplementedError) as cmex: |
| 112 | + selectable.compile(bind=self.crate_engine) |
| 113 | + self.assertEqual(str(cmex.exception), "Unsupported feature: ESCAPE is not supported") |
| 114 | + |
| 115 | + @skipIf(SA_VERSION < SA_1_4, "SQLAlchemy 1.3 and earlier do not support native `NOT ILIKE` compilation") |
| 116 | + def test_select_with_not_ilike_and_escape(self): |
| 117 | + """ |
| 118 | + Verify the compiler fails when using CrateDB's native `ILIKE` method together with `ESCAPE`. |
| 119 | + """ |
| 120 | + |
| 121 | + selectable = self.mytable.select().where(self.mytable.c.name.notilike("%foo%", escape='\\')) |
| 122 | + with self.assertRaises(NotImplementedError) as cmex: |
| 123 | + selectable.compile(bind=self.crate_engine) |
| 124 | + self.assertEqual(str(cmex.exception), "Unsupported feature: ESCAPE is not supported") |
| 125 | + |
74 | 126 | def test_select_with_offset(self):
|
75 | 127 | """
|
76 | 128 | Verify the `CrateCompiler.limit_clause` method, with offset.
|
|
0 commit comments