|
| 1 | +from sqlalchemy import select |
| 2 | +from sqlalchemy.sql.expression import bindparam |
| 3 | +from sqlalchemy.util.langhelpers import _symbol |
| 4 | +from tests import assertions |
| 5 | +from tests.setup import prepare_orm |
| 6 | + |
| 7 | +releases = [6, 7, 8] |
| 8 | + |
| 9 | + |
| 10 | +class TestSQLCompilationCaching: |
| 11 | + |
| 12 | + def test_sql_compilation_caching_1(self, settings): |
| 13 | + assertions.assert_solr_release(settings, releases) |
| 14 | + |
| 15 | + engine, t = prepare_orm(settings) |
| 16 | + |
| 17 | + qry_1 = (select(t.c.COUNTRY_s).select_from(t)).limit(1) |
| 18 | + qry_2 = (select(t.c.COUNTRY_s).select_from(t)).limit(10) |
| 19 | + |
| 20 | + with engine.connect() as connection: |
| 21 | + result_1 = connection.execute(qry_1) |
| 22 | + result_2 = connection.execute(qry_2) |
| 23 | + |
| 24 | + assert result_1.context.cache_hit == _symbol("NO_DIALECT_SUPPORT") |
| 25 | + assert result_2.context.cache_hit == _symbol("NO_DIALECT_SUPPORT") |
| 26 | + |
| 27 | + def test_sql_compilation_caching_2(self, settings): |
| 28 | + assertions.assert_solr_release(settings, releases) |
| 29 | + |
| 30 | + engine, t = prepare_orm(settings) |
| 31 | + |
| 32 | + qry_1 = (select(t.c.COUNTRY_s).select_from(t)).limit(1).offset(1) |
| 33 | + qry_2 = (select(t.c.COUNTRY_s).select_from(t)).limit(1).offset(2) |
| 34 | + |
| 35 | + with engine.connect() as connection: |
| 36 | + result_1 = connection.execute(qry_1) |
| 37 | + result_2 = connection.execute(qry_2) |
| 38 | + |
| 39 | + assert result_1.context.cache_hit == _symbol("NO_DIALECT_SUPPORT") |
| 40 | + assert result_2.context.cache_hit == _symbol("NO_DIALECT_SUPPORT") |
| 41 | + |
| 42 | + def test_sql_compilation_caching_3(self, settings): |
| 43 | + assertions.assert_solr_release(settings, releases) |
| 44 | + |
| 45 | + engine, t = prepare_orm(settings) |
| 46 | + |
| 47 | + qry = select(t).where(t.c.COUNTRY_s == bindparam("COUNTRY_s")).limit(10) |
| 48 | + |
| 49 | + with engine.connect() as connection: |
| 50 | + result_1 = connection.execute(qry, {"COUNTRY_s": "Sweden"}) |
| 51 | + result_2 = connection.execute(qry, {"COUNTRY_s": "France"}) |
| 52 | + |
| 53 | + assert result_1.context.cache_hit == _symbol("NO_DIALECT_SUPPORT") |
| 54 | + assert result_2.context.cache_hit == _symbol("NO_DIALECT_SUPPORT") |
0 commit comments