|
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 |
| -from unittest import mock, TestCase, skipIf |
| 22 | +from unittest import mock, skipIf |
23 | 23 |
|
24 | 24 | from crate.client.sqlalchemy.compiler import crate_before_execute
|
25 | 25 |
|
|
28 | 28 |
|
29 | 29 | from crate.client.sqlalchemy.sa_version import SA_VERSION, SA_1_4, SA_2_0
|
30 | 30 | from crate.client.sqlalchemy.types import ObjectType
|
| 31 | +from crate.client.test_util import ParametrizedTestCase |
31 | 32 |
|
32 | 33 |
|
33 |
| -class SqlAlchemyCompilerTest(TestCase): |
| 34 | +class SqlAlchemyCompilerTest(ParametrizedTestCase): |
34 | 35 |
|
35 | 36 | def setUp(self):
|
36 | 37 | self.crate_engine = sa.create_engine('crate://')
|
| 38 | + if isinstance(self.param, dict) and "server_version_info" in self.param: |
| 39 | + server_version_info = self.param["server_version_info"] |
| 40 | + self.crate_engine.dialect.server_version_info = server_version_info |
37 | 41 | self.sqlite_engine = sa.create_engine('sqlite://')
|
38 | 42 | self.metadata = sa.MetaData()
|
39 | 43 | self.mytable = sa.Table('mytable', self.metadata,
|
@@ -71,25 +75,32 @@ def test_bulk_update_on_builtin_type(self):
|
71 | 75 |
|
72 | 76 | self.assertFalse(hasattr(clauseelement, '_crate_specific'))
|
73 | 77 |
|
74 |
| - def test_select_with_ilike(self): |
| 78 | + def test_select_with_ilike_no_escape(self): |
75 | 79 | """
|
76 | 80 | Verify the compiler uses CrateDB's native `ILIKE` method.
|
77 | 81 | """
|
78 | 82 | selectable = self.mytable.select().where(self.mytable.c.name.ilike("%foo%"))
|
79 | 83 | 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 |
| 84 | + if self.crate_engine.dialect.has_ilike_operator(): |
| 85 | + self.assertEqual(statement, dedent(""" |
| 86 | + SELECT mytable.name, mytable.data |
| 87 | + FROM mytable |
| 88 | + WHERE mytable.name ILIKE ? |
| 89 | + """).strip()) # noqa: W291 |
| 90 | + else: |
| 91 | + self.assertEqual(statement, dedent(""" |
| 92 | + SELECT mytable.name, mytable.data |
| 93 | + FROM mytable |
| 94 | + WHERE lower(mytable.name) LIKE lower(?) |
| 95 | + """).strip()) # noqa: W291 |
85 | 96 |
|
86 |
| - def test_select_with_not_ilike(self): |
| 97 | + def test_select_with_not_ilike_no_escape(self): |
87 | 98 | """
|
88 | 99 | Verify the compiler uses CrateDB's native `ILIKE` method.
|
89 | 100 | """
|
90 | 101 | selectable = self.mytable.select().where(self.mytable.c.name.notilike("%foo%"))
|
91 | 102 | statement = str(selectable.compile(bind=self.crate_engine))
|
92 |
| - if SA_VERSION < SA_1_4: |
| 103 | + if SA_VERSION < SA_1_4 or not self.crate_engine.dialect.has_ilike_operator(): |
93 | 104 | self.assertEqual(statement, dedent("""
|
94 | 105 | SELECT mytable.name, mytable.data
|
95 | 106 | FROM mytable
|
|
0 commit comments