From 4ff4760fade8020df0418005e0fdd130ed3589a4 Mon Sep 17 00:00:00 2001 From: Gord Thompson Date: Sun, 4 Jul 2021 15:56:40 -0600 Subject: [PATCH] Modernize tests - select(whereclause) Change-Id: I306cfbea9920b35100e3087dcc21d7ffa6c39c55 --- lib/sqlalchemy/testing/suite/test_select.py | 4 +- lib/sqlalchemy/testing/warnings.py | 7 - test/dialect/mysql/test_compiler.py | 4 +- test/dialect/mysql/test_for_update.py | 92 ++++++------ test/dialect/oracle/test_compiler.py | 56 +++---- test/dialect/postgresql/test_compiler.py | 154 ++++++++++++-------- test/orm/inheritance/test_selects.py | 4 +- test/orm/test_bind.py | 12 +- test/orm/test_deprecations.py | 27 ++-- test/orm/test_eager_relations.py | 8 +- test/orm/test_froms.py | 36 +++-- test/orm/test_query.py | 2 +- test/orm/test_selectin_relations.py | 8 +- test/orm/test_subquery_relations.py | 8 +- test/orm/test_unitofwork.py | 15 +- test/sql/test_operators.py | 42 +++--- test/sql/test_query.py | 22 +-- test/sql/test_resultset.py | 18 ++- test/sql/test_selectable.py | 6 +- 19 files changed, 295 insertions(+), 230 deletions(-) diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py index 1605033a02..0a1227e584 100644 --- a/lib/sqlalchemy/testing/suite/test_select.py +++ b/lib/sqlalchemy/testing/suite/test_select.py @@ -1663,7 +1663,7 @@ class IsOrIsNotDistinctFromTest(fixtures.TablesTest): ) result = connection.execute( - tbl.select(tbl.c.col_a.is_distinct_from(tbl.c.col_b)) + tbl.select().where(tbl.c.col_a.is_distinct_from(tbl.c.col_b)) ).fetchall() eq_( len(result), @@ -1674,7 +1674,7 @@ class IsOrIsNotDistinctFromTest(fixtures.TablesTest): 1 if expected_row_count_for_is == 0 else 0 ) result = connection.execute( - tbl.select(tbl.c.col_a.is_not_distinct_from(tbl.c.col_b)) + tbl.select().where(tbl.c.col_a.is_not_distinct_from(tbl.c.col_b)) ).fetchall() eq_( len(result), diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py index df0e5aa5e5..8f9273b308 100644 --- a/lib/sqlalchemy/testing/warnings.py +++ b/lib/sqlalchemy/testing/warnings.py @@ -65,16 +65,9 @@ def setup_filters(): # be "error" however for I98b8defdf7c37b818b3824d02f7668e3f5f31c94 # we are moving one at a time for msg in [ - # - # Core execution - # - # r".*DefaultGenerator.execute\(\)", - # - # # # Core SQL constructs # - r"The FromClause\.select\(\).whereclause parameter is deprecated", r"Set functions such as union\(\), union_all\(\), extract\(\),", r"The legacy calling style of select\(\) is deprecated and will be " "removed", diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py index b0a6ee333c..6929d7d4e8 100644 --- a/test/dialect/mysql/test_compiler.py +++ b/test/dialect/mysql/test_compiler.py @@ -426,7 +426,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(of=table1), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(of=table1), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "FOR UPDATE", diff --git a/test/dialect/mysql/test_for_update.py b/test/dialect/mysql/test_for_update.py index 2f51747f51..1708c075e9 100644 --- a/test/dialect/mysql/test_for_update.py +++ b/test/dialect/mysql/test_for_update.py @@ -191,25 +191,27 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_basic(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update(), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s FOR UPDATE", ) def test_for_update_read(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - read=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(read=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s LOCK IN SHARE MODE", ) def test_for_update_skip_locked(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - skip_locked=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(skip_locked=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "FOR UPDATE SKIP LOCKED", @@ -217,9 +219,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_read_and_skip_locked(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - read=True, skip_locked=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(read=True, skip_locked=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "LOCK IN SHARE MODE SKIP LOCKED", @@ -227,9 +229,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_nowait(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - nowait=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "FOR UPDATE NOWAIT", @@ -237,9 +239,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_read_and_nowait(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - read=True, nowait=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(read=True, nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "LOCK IN SHARE MODE NOWAIT", @@ -247,9 +249,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_of_nowait(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - of=self.table1, nowait=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(of=self.table1, nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "FOR UPDATE OF mytable NOWAIT", @@ -258,9 +260,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_of_basic(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - of=self.table1 - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(of=self.table1), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "FOR UPDATE OF mytable", @@ -269,9 +271,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_of_skip_locked(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - of=self.table1, skip_locked=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(of=self.table1, skip_locked=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "FOR UPDATE OF mytable SKIP LOCKED", @@ -295,9 +297,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_of_column_list_aliased(self): ta = self.table1.alias() self.assert_compile( - ta.select(ta.c.myid == 7).with_for_update( - of=[ta.c.myid, ta.c.name] - ), + ta.select() + .where(ta.c.myid == 7) + .with_for_update(of=[ta.c.myid, ta.c.name]), "SELECT mytable_1.myid, mytable_1.name, mytable_1.description " "FROM mytable AS mytable_1 " "WHERE mytable_1.myid = %s FOR UPDATE OF mytable_1", @@ -325,9 +327,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_of_read_nowait(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - read=True, of=self.table1, nowait=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(read=True, of=self.table1, nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "LOCK IN SHARE MODE OF mytable NOWAIT", @@ -336,9 +338,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_of_read_skip_locked(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - read=True, of=self.table1, skip_locked=True - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(read=True, of=self.table1, skip_locked=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "LOCK IN SHARE MODE OF mytable SKIP LOCKED", @@ -347,7 +349,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_of_read_nowait_column_list(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update( read=True, of=[self.table1.c.myid, self.table1.c.name], nowait=True, @@ -360,9 +364,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_of_read(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - read=True, of=self.table1 - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(read=True, of=self.table1), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "LOCK IN SHARE MODE OF mytable", @@ -371,9 +375,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update_textual_of(self): self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - of=text("mytable") - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(of=text("mytable")), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "FOR UPDATE OF mytable", @@ -381,9 +385,9 @@ class MySQLForUpdateCompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - self.table1.select(self.table1.c.myid == 7).with_for_update( - of=literal_column("mytable") - ), + self.table1.select() + .where(self.table1.c.myid == 7) + .with_for_update(of=literal_column("mytable")), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %s " "FOR UPDATE OF mytable", diff --git a/test/dialect/oracle/test_compiler.py b/test/dialect/oracle/test_compiler.py index 2bbc14e99a..e41a770ed4 100644 --- a/test/dialect/oracle/test_compiler.py +++ b/test/dialect/oracle/test_compiler.py @@ -379,46 +379,50 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(), + table1.select().where(table1.c.myid == 7).with_for_update(), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - of=table1.c.myid - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(of=table1.c.myid), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 " "FOR UPDATE OF mytable.myid", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(nowait=True), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - nowait=True, of=table1.c.myid - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(nowait=True, of=table1.c.myid), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 " "FOR UPDATE OF mytable.myid NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - nowait=True, of=[table1.c.myid, table1.c.name] - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(nowait=True, of=[table1.c.myid, table1.c.name]), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE OF " "mytable.myid, mytable.name NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( skip_locked=True, of=[table1.c.myid, table1.c.name] ), "SELECT mytable.myid, mytable.name, mytable.description " @@ -428,25 +432,27 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # key_share has no effect self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(key_share=True), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(key_share=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE", ) # read has no effect self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, key_share=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, key_share=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE", ) ta = table1.alias() self.assert_compile( - ta.select(ta.c.myid == 7).with_for_update( - of=[ta.c.myid, ta.c.name] - ), + ta.select() + .where(ta.c.myid == 7) + .with_for_update(of=[ta.c.myid, ta.c.name]), "SELECT mytable_1.myid, mytable_1.name, mytable_1.description " "FROM mytable mytable_1 " "WHERE mytable_1.myid = :myid_1 FOR UPDATE OF " @@ -455,18 +461,18 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # ensure of=text() for of works self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, of=text("table1") - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, of=text("table1")), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE OF table1", ) # ensure of=literal_column() for of works self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, of=literal_column("table1") - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, of=literal_column("table1")), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE OF table1", ) diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index e48de9d21d..d75030ee0c 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -1034,87 +1034,93 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(), + table1.select().where(table1.c.myid == 7).with_for_update(), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s FOR UPDATE", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(nowait=True), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s FOR UPDATE NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - skip_locked=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(skip_locked=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR UPDATE SKIP LOCKED", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(read=True), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s FOR SHARE", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, nowait=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s FOR SHARE NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - key_share=True, nowait=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(key_share=True, nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR NO KEY UPDATE NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - key_share=True, read=True, nowait=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(key_share=True, read=True, nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR KEY SHARE NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, skip_locked=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, skip_locked=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR SHARE SKIP LOCKED", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - of=table1.c.myid - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(of=table1.c.myid), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR UPDATE OF mytable", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, nowait=True, of=table1 - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, nowait=True, of=table1), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR SHARE OF mytable NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( key_share=True, read=True, nowait=True, of=table1 ), "SELECT mytable.myid, mytable.name, mytable.description " @@ -1123,16 +1129,18 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, nowait=True, of=table1.c.myid - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, nowait=True, of=table1.c.myid), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR SHARE OF mytable NOWAIT", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( read=True, nowait=True, of=[table1.c.myid, table1.c.name] ), "SELECT mytable.myid, mytable.name, mytable.description " @@ -1141,7 +1149,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( read=True, skip_locked=True, of=[table1.c.myid, table1.c.name], @@ -1153,7 +1163,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( skip_locked=True, of=[table1.c.myid, table1.c.name] ), "SELECT mytable.myid, mytable.name, mytable.description " @@ -1162,7 +1174,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( read=True, skip_locked=True, of=[table1.c.myid, table1.c.name] ), "SELECT mytable.myid, mytable.name, mytable.description " @@ -1171,7 +1185,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( key_share=True, nowait=True, of=[table1.c.myid, table1.c.name] ), "SELECT mytable.myid, mytable.name, mytable.description " @@ -1180,7 +1196,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( key_share=True, skip_locked=True, of=[table1.c.myid, table1.c.name], @@ -1191,7 +1209,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( + table1.select() + .where(table1.c.myid == 7) + .with_for_update( key_share=True, of=[table1.c.myid, table1.c.name] ), "SELECT mytable.myid, mytable.name, mytable.description " @@ -1200,52 +1220,54 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(key_share=True), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(key_share=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR NO KEY UPDATE", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, key_share=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, key_share=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR KEY SHARE", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, key_share=True, of=table1 - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, key_share=True, of=table1), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR KEY SHARE OF mytable", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, of=table1 - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, of=table1), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR SHARE OF mytable", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - read=True, key_share=True, skip_locked=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(read=True, key_share=True, skip_locked=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR KEY SHARE SKIP LOCKED", ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - key_share=True, skip_locked=True - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(key_share=True, skip_locked=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR NO KEY UPDATE SKIP LOCKED", @@ -1253,9 +1275,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ta = table1.alias() self.assert_compile( - ta.select(ta.c.myid == 7).with_for_update( - of=[ta.c.myid, ta.c.name] - ), + ta.select() + .where(ta.c.myid == 7) + .with_for_update(of=[ta.c.myid, ta.c.name]), "SELECT mytable_1.myid, mytable_1.name, mytable_1.description " "FROM mytable AS mytable_1 " "WHERE mytable_1.myid = %(myid_1)s FOR UPDATE OF mytable_1", @@ -1264,7 +1286,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): table2 = table("table2", column("mytable_id")) join = table2.join(table1, table2.c.mytable_id == table1.c.myid) self.assert_compile( - join.select(table2.c.mytable_id == 7).with_for_update(of=[join]), + join.select() + .where(table2.c.mytable_id == 7) + .with_for_update(of=[join]), "SELECT table2.mytable_id, " "mytable.myid, mytable.name, mytable.description " "FROM table2 " @@ -1275,7 +1299,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): join = table2.join(ta, table2.c.mytable_id == ta.c.myid) self.assert_compile( - join.select(table2.c.mytable_id == 7).with_for_update(of=[join]), + join.select() + .where(table2.c.mytable_id == 7) + .with_for_update(of=[join]), "SELECT table2.mytable_id, " "mytable_1.myid, mytable_1.name, mytable_1.description " "FROM table2 " @@ -1287,9 +1313,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # ensure of=text() for of works self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - of=text("table1") - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(of=text("table1")), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR UPDATE OF table1", @@ -1297,9 +1323,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # ensure literal_column of works self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update( - of=literal_column("table1") - ), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(of=literal_column("table1")), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s " "FOR UPDATE OF table1", @@ -1312,7 +1338,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(of=table1), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(of=table1), "SELECT testschema.mytable.myid, testschema.mytable.name " "FROM testschema.mytable " "WHERE testschema.mytable.myid = %(myid_1)s " diff --git a/test/orm/inheritance/test_selects.py b/test/orm/inheritance/test_selects.py index 24297dd0eb..4f6c4a8bd4 100644 --- a/test/orm/inheritance/test_selects.py +++ b/test/orm/inheritance/test_selects.py @@ -21,8 +21,8 @@ class InheritingSelectablesTest(fixtures.MappedTest): Column("b", String(30), nullable=0), ) - cls.tables.bar = foo.select(foo.c.b == "bar").alias("bar") - cls.tables.baz = foo.select(foo.c.b == "baz").alias("baz") + cls.tables.bar = foo.select().where(foo.c.b == "bar").alias("bar") + cls.tables.baz = foo.select().where(foo.c.b == "baz").alias("baz") def test_load(self, connection): foo, bar, baz = self.tables.foo, self.tables.bar, self.tables.baz diff --git a/test/orm/test_bind.py b/test/orm/test_bind.py index f448e2c529..f584f22aea 100644 --- a/test/orm/test_bind.py +++ b/test/orm/test_bind.py @@ -73,13 +73,15 @@ class BindIntegrationTest(_fixtures.FixtureTest): sess.execute(users_unbound.insert(), params=dict(id=2, name="jack")) eq_( sess.execute( - users_unbound.select(users_unbound.c.id == 2) + users_unbound.select().where(users_unbound.c.id == 2) ).fetchall(), [(2, "jack")], ) eq_( - sess.execute(users_unbound.select(User.id == 2)).fetchall(), + sess.execute( + users_unbound.select().where(User.id == 2) + ).fetchall(), [(2, "jack")], ) @@ -133,13 +135,15 @@ class BindIntegrationTest(_fixtures.FixtureTest): eq_( sess.execute( - users_unbound.select(users_unbound.c.id == 2) + users_unbound.select().where(users_unbound.c.id == 2) ).fetchall(), [(2, "jack")], ) eq_( - sess.execute(users_unbound.select(User.id == 2)).fetchall(), + sess.execute( + users_unbound.select().where(User.id == 2) + ).fetchall(), [(2, "jack")], ) diff --git a/test/orm/test_deprecations.py b/test/orm/test_deprecations.py index c7561e8046..2081f4f0a2 100644 --- a/test/orm/test_deprecations.py +++ b/test/orm/test_deprecations.py @@ -506,8 +506,9 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL): ) query = ( - users.select(users.c.id == 7) - .union(users.select(users.c.id > 7)) + users.select() + .where(users.c.id == 7) + .union(users.select().where(users.c.id > 7)) .alias("ulist") .outerjoin(addresses) .select(order_by=[text("ulist.id"), addresses.c.id]) @@ -541,8 +542,9 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL): # the adapter created by contains_eager() adalias = addresses.alias() query = ( - users.select(users.c.id == 7) - .union(users.select(users.c.id > 7)) + users.select() + .where(users.c.id == 7) + .union(users.select().where(users.c.id > 7)) .alias("ulist") .outerjoin(adalias) .select(order_by=[text("ulist.id"), adalias.c.id]) @@ -616,7 +618,7 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL): # mapper(User, users, properties={"addresses": relationship(Address)}) # mapper(Address, addresses) - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) sess = fixture_session() with self._expect_implicit_subquery(): @@ -693,7 +695,7 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL): ) sess = fixture_session() - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) with self._expect_implicit_subquery(): eq_( @@ -718,7 +720,7 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL): def test_join_no_order_by(self): User, users = self.classes.User, self.tables.users - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) sess = fixture_session() with self._expect_implicit_subquery(): @@ -734,7 +736,7 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL): self.classes.User, ) - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) sess = fixture_session() def go(): @@ -3297,8 +3299,9 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): ) query = ( - users.select(users.c.id == 7) - .union(users.select(users.c.id > 7)) + users.select() + .where(users.c.id == 7) + .union(users.select().where(users.c.id > 7)) .alias("ulist") .outerjoin(addresses) .select(order_by=[text("ulist.id"), addresses.c.id]) @@ -3746,7 +3749,7 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): with testing.expect_deprecated(r"Query.values?\(\) is deprecated"): assert list(sess.query(User).values()) == list() - sel = users.select(User.id.in_([7, 8])).alias() + sel = users.select().where(User.id.in_([7, 8])).alias() q = sess.query(User) with testing.expect_deprecated(r"Query.values?\(\) is deprecated"): q2 = q.select_entity_from(sel).values(User.name) @@ -3854,7 +3857,7 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): with testing.expect_deprecated(r"Query.values?\(\) is deprecated"): assert list(sess.query(User).values()) == list() - sel = users.select(User.id.in_([7, 8])).alias() + sel = users.select().where(User.id.in_([7, 8])).alias() q = sess.query(User) u2 = aliased(User) with testing.expect_deprecated(r"Query.values?\(\) is deprecated"): diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py index e52af90b91..8a41160838 100644 --- a/test/orm/test_eager_relations.py +++ b/test/orm/test_eager_relations.py @@ -1967,9 +1967,11 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): .alias("max_orders_by_user") ) - max_orders = orders.select( - orders.c.id == max_orders_by_user.c.order_id - ).alias("max_orders") + max_orders = ( + orders.select() + .where(orders.c.id == max_orders_by_user.c.order_id) + .alias("max_orders") + ) mapper(Order, orders) mapper( diff --git a/test/orm/test_froms.py b/test/orm/test_froms.py index 5881c54c2a..9496f57bcf 100644 --- a/test/orm/test_froms.py +++ b/test/orm/test_froms.py @@ -1078,8 +1078,9 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): ) query = ( - users.select(users.c.id == 7) - .union(users.select(users.c.id > 7)) + users.select() + .where(users.c.id == 7) + .union(users.select().where(users.c.id > 7)) .alias("ulist") .outerjoin(addresses) .select(order_by=[text("ulist.id"), addresses.c.id]) @@ -1105,8 +1106,9 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): ) query = ( - users.select(users.c.id == 7) - .union(users.select(users.c.id > 7)) + users.select() + .where(users.c.id == 7) + .union(users.select().where(users.c.id > 7)) .alias("ulist") .outerjoin(addresses) .select(order_by=[text("ulist.id"), addresses.c.id]) @@ -1134,8 +1136,9 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): ) query = ( - users.select(users.c.id == 7) - .union(users.select(users.c.id > 7)) + users.select() + .where(users.c.id == 7) + .union(users.select().where(users.c.id > 7)) .alias("ulist") .outerjoin(addresses) .select(order_by=[text("ulist.id"), addresses.c.id]) @@ -1168,8 +1171,9 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): # the adapter created by contains_eager() adalias = addresses.alias() query = ( - users.select(users.c.id == 7) - .union(users.select(users.c.id > 7)) + users.select() + .where(users.c.id == 7) + .union(users.select().where(users.c.id > 7)) .alias("ulist") .outerjoin(adalias) .select(order_by=[text("ulist.id"), adalias.c.id]) @@ -1704,7 +1708,7 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): ) sess = fixture_session() - sel = users.select(User.id.in_([7, 8])).alias() + sel = users.select().where(User.id.in_([7, 8])).alias() q = sess.query(User.name) q2 = q.select_entity_from(sel).all() eq_(list(q2), [("jack",), ("ed",)]) @@ -2653,7 +2657,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): mapper(User, users, properties={"addresses": relationship(Address)}) mapper(Address, addresses) - sel = users.select(users.c.id.in_([7, 8])).alias() + sel = users.select().where(users.c.id.in_([7, 8])).alias() sess = fixture_session() eq_( @@ -2879,7 +2883,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): mapper(User, users) - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) sess = fixture_session() eq_( @@ -2957,7 +2961,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): mapper(User, users, properties={"addresses": relationship(Address)}) mapper(Address, addresses) - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) sess = fixture_session() eq_( @@ -3069,7 +3073,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): mapper(Keyword, keywords) sess = fixture_session() - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) eq_( sess.query(User) @@ -3132,7 +3136,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): sess = fixture_session() - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) def go(): eq_( @@ -3212,7 +3216,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): self.assert_sql_count(testing.db, go, 1) sess.expunge_all() - sel2 = orders.select(orders.c.id.in_([1, 2, 3])) + sel2 = orders.select().where(orders.c.id.in_([1, 2, 3])) eq_( sess.query(Order) .select_entity_from(sel2.subquery()) @@ -3244,7 +3248,7 @@ class SelectFromTest(QueryTest, AssertsCompiledSQL): ) mapper(Address, addresses) - sel = users.select(users.c.id.in_([7, 8])) + sel = users.select().where(users.c.id.in_([7, 8])) sess = fixture_session() def go(): diff --git a/test/orm/test_query.py b/test/orm/test_query.py index ed70557661..a30d0ef7e6 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -1133,7 +1133,7 @@ class GetTest(QueryTest): class SomeUser(object): pass - s = users.select(users.c.id != 12).alias("users") + s = users.select().where(users.c.id != 12).alias("users") m = mapper(SomeUser, s) assert s.primary_key == m.primary_key diff --git a/test/orm/test_selectin_relations.py b/test/orm/test_selectin_relations.py index 233ca5423d..4dbd269996 100644 --- a/test/orm/test_selectin_relations.py +++ b/test/orm/test_selectin_relations.py @@ -1344,9 +1344,11 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): .alias("max_orders_by_user") ) - max_orders = orders.select( - orders.c.id == max_orders_by_user.c.order_id - ).alias("max_orders") + max_orders = ( + orders.select() + .where(orders.c.id == max_orders_by_user.c.order_id) + .alias("max_orders") + ) mapper(Order, orders) mapper( diff --git a/test/orm/test_subquery_relations.py b/test/orm/test_subquery_relations.py index 512ec0fe2b..2115cf4d85 100644 --- a/test/orm/test_subquery_relations.py +++ b/test/orm/test_subquery_relations.py @@ -1375,9 +1375,11 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): .alias("max_orders_by_user") ) - max_orders = orders.select( - orders.c.id == max_orders_by_user.c.order_id - ).alias("max_orders") + max_orders = ( + orders.select() + .where(orders.c.id == max_orders_by_user.c.order_id) + .alias("max_orders") + ) mapper(Order, orders) mapper( diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index ff8349fee9..2f2586556d 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -1525,14 +1525,13 @@ class OneToManyTest(_fixtures.FixtureTest): conn = session.connection() user_rows = conn.execute( - users.select(users.c.id.in_([u.id])) + users.select().where(users.c.id.in_([u.id])) ).fetchall() eq_(list(user_rows[0]), [u.id, "one2manytester"]) address_rows = conn.execute( - addresses.select( + addresses.select(order_by=[addresses.c.email_address]).where( addresses.c.id.in_([a.id, a2.id]), - order_by=[addresses.c.email_address], ) ).fetchall() eq_(list(address_rows[0]), [a2.id, u.id, "lala@test.org"]) @@ -1546,7 +1545,7 @@ class OneToManyTest(_fixtures.FixtureTest): session.flush() address_rows = conn.execute( - addresses.select(addresses.c.id == addressid) + addresses.select().where(addresses.c.id == addressid) ).fetchall() eq_(list(address_rows[0]), [addressid, userid, "somethingnew@foo.com"]) self.assert_(u.id == userid and a2.id == addressid) @@ -2086,11 +2085,11 @@ class SaveTest(_fixtures.FixtureTest): conn = session.connection() user_rows = conn.execute( - users.select(users.c.id.in_([u.foo_id])) + users.select().where(users.c.id.in_([u.foo_id])) ).fetchall() eq_(list(user_rows[0]), [u.foo_id, "multitester"]) address_rows = conn.execute( - addresses.select(addresses.c.id.in_([u.id])) + addresses.select().where(addresses.c.id.in_([u.id])) ).fetchall() eq_(list(address_rows[0]), [u.id, u.foo_id, "multi@test.org"]) @@ -2099,11 +2098,11 @@ class SaveTest(_fixtures.FixtureTest): session.flush() user_rows = conn.execute( - users.select(users.c.id.in_([u.foo_id])) + users.select().where(users.c.id.in_([u.foo_id])) ).fetchall() eq_(list(user_rows[0]), [u.foo_id, "imnew"]) address_rows = conn.execute( - addresses.select(addresses.c.id.in_([u.id])) + addresses.select().where(addresses.c.id.in_([u.id])) ).fetchall() eq_(list(address_rows[0]), [u.id, u.foo_id, "lala@hey.com"]) diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 43d9133a79..b2ba7ae734 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -1355,13 +1355,15 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_operator_precedence_1(self): self.assert_compile( - self.table2.select((self.table2.c.field == 5) == None), # noqa + self.table2.select().where( + (self.table2.c.field == 5) == None + ), # noqa "SELECT op.field FROM op WHERE (op.field = :field_1) IS NULL", ) def test_operator_precedence_2(self): self.assert_compile( - self.table2.select( + self.table2.select().where( (self.table2.c.field + 5) == self.table2.c.field ), "SELECT op.field FROM op WHERE op.field + :field_1 = op.field", @@ -1369,33 +1371,33 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_operator_precedence_3(self): self.assert_compile( - self.table2.select((self.table2.c.field + 5) * 6), + self.table2.select().where((self.table2.c.field + 5) * 6), "SELECT op.field FROM op WHERE (op.field + :field_1) * :param_1", ) def test_operator_precedence_4(self): self.assert_compile( - self.table2.select((self.table2.c.field * 5) + 6), + self.table2.select().where((self.table2.c.field * 5) + 6), "SELECT op.field FROM op WHERE op.field * :field_1 + :param_1", ) def test_operator_precedence_5(self): self.assert_compile( - self.table2.select(5 + self.table2.c.field.in_([5, 6])), + self.table2.select().where(5 + self.table2.c.field.in_([5, 6])), "SELECT op.field FROM op WHERE :param_1 + " "(op.field IN ([POSTCOMPILE_field_1]))", ) def test_operator_precedence_6(self): self.assert_compile( - self.table2.select((5 + self.table2.c.field).in_([5, 6])), + self.table2.select().where((5 + self.table2.c.field).in_([5, 6])), "SELECT op.field FROM op WHERE :field_1 + op.field " "IN ([POSTCOMPILE_param_1])", ) def test_operator_precedence_7(self): self.assert_compile( - self.table2.select( + self.table2.select().where( not_(and_(self.table2.c.field == 5, self.table2.c.field == 7)) ), "SELECT op.field FROM op WHERE NOT " @@ -1404,26 +1406,28 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_operator_precedence_8(self): self.assert_compile( - self.table2.select(not_(self.table2.c.field == 5)), + self.table2.select().where(not_(self.table2.c.field == 5)), "SELECT op.field FROM op WHERE op.field != :field_1", ) def test_operator_precedence_9(self): self.assert_compile( - self.table2.select(not_(self.table2.c.field.between(5, 6))), + self.table2.select().where( + not_(self.table2.c.field.between(5, 6)) + ), "SELECT op.field FROM op WHERE " "op.field NOT BETWEEN :field_1 AND :field_2", ) def test_operator_precedence_10(self): self.assert_compile( - self.table2.select(not_(self.table2.c.field) == 5), + self.table2.select().where(not_(self.table2.c.field) == 5), "SELECT op.field FROM op WHERE (NOT op.field) = :param_1", ) def test_operator_precedence_11(self): self.assert_compile( - self.table2.select( + self.table2.select().where( (self.table2.c.field == self.table2.c.field).between( False, True ) @@ -1434,7 +1438,7 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_operator_precedence_12(self): self.assert_compile( - self.table2.select( + self.table2.select().where( between( (self.table2.c.field == self.table2.c.field), False, True ) @@ -1445,7 +1449,7 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_operator_precedence_13(self): self.assert_compile( - self.table2.select( + self.table2.select().where( self.table2.c.field.match(self.table2.c.field).is_(None) ), "SELECT op.field FROM op WHERE (op.field MATCH op.field) IS NULL", @@ -1514,7 +1518,9 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_op_operators(self): self.assert_compile( - self.table1.select(self.table1.c.myid.op("hoho")(12) == 14), + self.table1.select().where( + self.table1.c.myid.op("hoho")(12) == 14 + ), "SELECT mytable.myid, mytable.name, mytable.description FROM " "mytable WHERE (mytable.myid hoho :myid_1) = :param_1", ) @@ -2319,7 +2325,7 @@ class NegationTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_negate_operators_2(self): self.assert_compile( - self.table1.select( + self.table1.select().where( (self.table1.c.myid != 12) & ~(self.table1.c.name == "john") ), "SELECT mytable.myid, mytable.name FROM " @@ -2329,7 +2335,7 @@ class NegationTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_negate_operators_3(self): self.assert_compile( - self.table1.select( + self.table1.select().where( (self.table1.c.myid != 12) & ~(self.table1.c.name.between("jack", "john")) ), @@ -2340,7 +2346,7 @@ class NegationTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_negate_operators_4(self): self.assert_compile( - self.table1.select( + self.table1.select().where( (self.table1.c.myid != 12) & ~and_( self.table1.c.name == "john", @@ -2356,7 +2362,7 @@ class NegationTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_negate_operators_5(self): self.assert_compile( - self.table1.select( + self.table1.select().where( (self.table1.c.myid != 12) & ~self.table1.c.name ), "SELECT mytable.myid, mytable.name FROM " diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 14dc397f68..b3d728ab36 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -309,7 +309,9 @@ class QueryTest(fixtures.TablesTest): connection.execute(users.insert(), dict(user_id=8, user_name="fred")) u = bindparam("userid") - s = users.select(and_(users.c.user_name == u, users.c.user_name == u)) + s = users.select().where( + and_(users.c.user_name == u, users.c.user_name == u) + ) r = connection.execute(s, dict(userid="fred")).fetchall() assert len(r) == 1 @@ -581,20 +583,20 @@ class QueryTest(fixtures.TablesTest): connection.execute(users.insert(), dict(user_id=8, user_name="fred")) connection.execute(users.insert(), dict(user_id=9, user_name=None)) - s = users.select(users.c.user_name.in_([])) + s = users.select().where(users.c.user_name.in_([])) r = connection.execute(s).fetchall() # No username is in empty set assert len(r) == 0 - s = users.select(not_(users.c.user_name.in_([]))) + s = users.select().where(not_(users.c.user_name.in_([]))) r = connection.execute(s).fetchall() assert len(r) == 3 - s = users.select(users.c.user_name.in_(["jack", "fred"])) + s = users.select().where(users.c.user_name.in_(["jack", "fred"])) r = connection.execute(s).fetchall() assert len(r) == 2 - s = users.select(not_(users.c.user_name.in_(["jack", "fred"]))) + s = users.select().where(not_(users.c.user_name.in_(["jack", "fred"]))) r = connection.execute(s).fetchall() # Null values are not outside any set assert len(r) == 0 @@ -842,7 +844,7 @@ class QueryTest(fixtures.TablesTest): u = bindparam("search_key", type_=String) - s = users.select(not_(u.in_([]))) + s = users.select().where(not_(u.in_([]))) r = connection.execute(s, dict(search_key="john")).fetchall() assert len(r) == 3 r = connection.execute(s, dict(search_key=None)).fetchall() @@ -857,7 +859,7 @@ class QueryTest(fixtures.TablesTest): connection.execute(users.insert(), dict(user_id=8, user_name="fred")) connection.execute(users.insert(), dict(user_id=9, user_name=None)) - s = users.select(not_(literal("john").in_([]))) + s = users.select().where(not_(literal("john").in_([]))) r = connection.execute(s).fetchall() assert len(r) == 3 @@ -879,13 +881,13 @@ class QueryTest(fixtures.TablesTest): ], ) - s = users.select(users.c.user_name.in_([]) == True) # noqa + s = users.select().where(users.c.user_name.in_([]) == True) # noqa r = connection.execute(s).fetchall() assert len(r) == 0 - s = users.select(users.c.user_name.in_([]) == False) # noqa + s = users.select().where(users.c.user_name.in_([]) == False) # noqa r = connection.execute(s).fetchall() assert len(r) == 3 - s = users.select(users.c.user_name.in_([]) == None) # noqa + s = users.select().where(users.c.user_name.in_([]) == None) # noqa r = connection.execute(s).fetchall() assert len(r) == 0 diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 892cfee535..b1ede060df 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -391,7 +391,9 @@ class CursorResultTest(fixtures.TablesTest): ], ) - r = connection.execute(users.select(users.c.user_id == 2)).first() + r = connection.execute( + users.select().where(users.c.user_id == 2) + ).first() eq_(r.user_id, 2) eq_(r._mapping["user_id"], 2) eq_(r._mapping[users.c.user_id], 2) @@ -411,7 +413,9 @@ class CursorResultTest(fixtures.TablesTest): ], ) - r = connection.execute(users.select(users.c.user_id == 2)).first() + r = connection.execute( + users.select().where(users.c.user_id == 2) + ).first() eq_(r.user_id, 2) eq_(r._mapping["user_id"], 2) @@ -766,7 +770,9 @@ class CursorResultTest(fixtures.TablesTest): users = self.tables.users connection.execute(users.insert(), dict(user_id=1, user_name="john")) - r = connection.execute(users.select(users.c.user_id == 1)).first() + r = connection.execute( + users.select().where(users.c.user_id == 1) + ).first() connection.execute(users.delete()) connection.execute(users.insert(), r._mapping) eq_(connection.execute(users.select()).fetchall(), [(1, "john")]) @@ -1241,7 +1247,9 @@ class CursorResultTest(fixtures.TablesTest): users = self.tables.users connection.execute(users.insert(), dict(user_id=1, user_name="foo")) - r = connection.execute(users.select(users.c.user_id == 1)).first() + r = connection.execute( + users.select().where(users.c.user_id == 1) + ).first() eq_(r[0], 1) eq_(r[1], "foo") eq_([x.lower() for x in r._fields], ["user_id", "user_name"]) @@ -1288,7 +1296,7 @@ class CursorResultTest(fixtures.TablesTest): ), ) r = connection.execute( - shadowed.select(shadowed.c.shadow_id == 1) + shadowed.select().where(shadowed.c.shadow_id == 1) ).first() eq_(r.shadow_id, 1) diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index efa3be5237..00ef92efb8 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -2422,9 +2422,9 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): item_join = polymorphic_union( { - "BaseItem": base_item_table.select( - base_item_table.c.child_name == "BaseItem" - ).subquery(), + "BaseItem": base_item_table.select() + .where(base_item_table.c.child_name == "BaseItem") + .subquery(), "Item": base_item_table.join(item_table), }, None, -- 2.47.2