def _assert_all_selectin(self, q): result = self.assert_sql_execution( testing.db, q.all, CompiledSQL( "SELECT a.id AS a_id, a.adata AS a_adata, " "a.type AS a_type FROM a ORDER BY a.id", {}), AllOf( EachOf( CompiledSQL( "SELECT asub.id AS asub_id, a.id AS a_id, a.type AS a_type, " "asub.asubdata AS asub_asubdata FROM a JOIN asub " "ON a.id = asub.id WHERE a.id IN ([EXPANDING_primary_keys]) " "ORDER BY a.id", {"primary_keys": [2]}), CompiledSQL( # note this links c.a_sub_id to a.id, even though # primaryjoin is to asub.id. this is because the # cols a.id / asub.id are listed in the mapper's # equivalent_columns so they are guaranteed to store # the same value. "SELECT c.a_sub_id AS c_a_sub_id, " "c.id AS c_id " "FROM c WHERE c.a_sub_id " "IN ([EXPANDING_primary_keys]) ORDER BY c.a_sub_id", {"primary_keys": [2]}), ), CompiledSQL( "SELECT b.a_id AS b_a_id, b.id AS b_id FROM b " "WHERE b.a_id IN ([EXPANDING_primary_keys]) " "ORDER BY b.a_id", {"primary_keys": [1, 2]}))) self.assert_sql_execution( testing.db, lambda: self._run_query(result), )
def test_drop_ordering_single_table(self): with self.sql_execution_asserter(testing.db) as asserter: for table in self.tables_test_metadata.tables.values(): table.drop(testing.db, checkfirst=False) asserter.assert_( AllOf( CompiledSQL("DROP TABLE t_seq_test_2", {}), EachOf( CompiledSQL("DROP TABLE t_seq_test", {}), CompiledSQL("DROP SEQUENCE t_seq", {}), ), ))
def _assert_all_selectin(self, q): result = self.assert_sql_execution( testing.db, q.all, CompiledSQL( "SELECT a.id AS a_id, a.adata AS a_adata, " "a.type AS a_type FROM a ORDER BY a.id", {} ), AllOf( EachOf( CompiledSQL( "SELECT asub.id AS asub_id, a.id AS a_id, a.type AS a_type, " "asub.asubdata AS asub_asubdata FROM a JOIN asub " "ON a.id = asub.id WHERE a.id IN ([EXPANDING_primary_keys]) " "ORDER BY a.id", {"primary_keys": [2]} ), CompiledSQL( "SELECT anon_1.a_id AS anon_1_a_id, c.id AS c_id, " "c.a_sub_id AS c_a_sub_id FROM (SELECT a.id AS a_id, a.adata " "AS a_adata, a.type AS a_type, asub.id AS asub_id, " "asub.asubdata AS asub_asubdata FROM a JOIN asub " "ON a.id = asub.id) AS anon_1 JOIN c " "ON anon_1.asub_id = c.a_sub_id " "WHERE anon_1.a_id IN ([EXPANDING_primary_keys]) " "ORDER BY anon_1.a_id", {"primary_keys": [2]} ), ), CompiledSQL( "SELECT a_1.id AS a_1_id, b.id AS b_id, b.a_id AS b_a_id " "FROM a AS a_1 JOIN b ON a_1.id = b.a_id " "WHERE a_1.id IN ([EXPANDING_primary_keys]) ORDER BY a_1.id", {"primary_keys": [1, 2]} ) ) ) self.assert_sql_execution( testing.db, lambda: self._run_query(result), )
def test_drop_ordering(self): with self.sql_execution_asserter(testing.db) as asserter: self.metadata.drop_all(checkfirst=False) asserter.assert_( AllOf( CompiledSQL("DROP TABLE t_seq_test_2", {}), EachOf( CompiledSQL("DROP TABLE t_seq_test", {}), CompiledSQL( "DROP SEQUENCE t_seq", # dropped as part of t_seq_test {}, ), ), ), CompiledSQL( "DROP SEQUENCE t_seq_2", # dropped as part of metadata level {}, ), )