def test_join_condition_ignore_nonexistent_tables(self): m = MetaData() t1 = Table("t1", m, Column("id", Integer)) t2 = Table("t2", m, Column("id", Integer), Column("t1id", ForeignKey("t1.id"))) with testing.expect_deprecated( "The join_condition.ignore_nonexistent_tables " "parameter is deprecated"): join_cond = sql_util.join_condition(t1, t2, ignore_nonexistent_tables=True) t1t2 = t1.join(t2) assert t1t2.onclause.compare(join_cond)
def test_join(self): # Lower case names, should not quote metadata = MetaData() t1 = Table("t1", metadata, Column("col1", Integer)) t2 = Table( "t2", metadata, Column("col1", Integer), Column("t1col1", Integer, ForeignKey("t1.col1")), ) self.assert_compile( t2.join(t1).select(), "SELECT " "t2.col1, t2.t1col1, t1.col1 " "FROM " "t2 " "JOIN " "t1 ON t1.col1 = t2.t1col1", ) # Lower case names, quotes on, should quote metadata = MetaData() t1 = Table( "t1", metadata, Column("col1", Integer, quote=True), quote=True ) t2 = Table( "t2", metadata, Column("col1", Integer, quote=True), Column("t1col1", Integer, ForeignKey("t1.col1"), quote=True), quote=True, ) self.assert_compile( t2.join(t1).select(), "SELECT " '"t2"."col1", "t2"."t1col1", "t1"."col1" ' "FROM " '"t2" ' "JOIN " '"t1" ON "t1"."col1" = "t2"."t1col1"', ) # Not lower case names, should quote metadata = MetaData() t1 = Table("T1", metadata, Column("Col1", Integer)) t2 = Table( "T2", metadata, Column("Col1", Integer), Column("T1Col1", Integer, ForeignKey("T1.Col1")), ) self.assert_compile( t2.join(t1).select(), "SELECT " '"T2"."Col1", "T2"."T1Col1", "T1"."Col1" ' "FROM " '"T2" ' "JOIN " '"T1" ON "T1"."Col1" = "T2"."T1Col1"', ) # Not lower case names, quotes off, should not quote metadata = MetaData() t1 = Table( "T1", metadata, Column("Col1", Integer, quote=False), quote=False ) t2 = Table( "T2", metadata, Column("Col1", Integer, quote=False), Column("T1Col1", Integer, ForeignKey("T1.Col1"), quote=False), quote=False, ) self.assert_compile( t2.join(t1).select(), "SELECT " "T2.Col1, T2.T1Col1, T1.Col1 " "FROM " "T2 " "JOIN " "T1 ON T1.Col1 = T2.T1Col1", )