Skip to content

Commit

Permalink
Add tests for MySqlDbColumn.TableName.
Browse files Browse the repository at this point in the history
Signed-off-by: Bradley Grainger <[email protected]>
  • Loading branch information
bgrainger committed Oct 28, 2024
1 parent 02bcc0f commit fb239d6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/IntegrationTests/QueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,48 @@ public void GetColumnSchemaAfterNextResult()
Assert.False(reader.NextResult());
Assert.Empty(reader.GetColumnSchema());
}

[Fact]
public void GetColumnSchemaForTableAlias()
{
using var cmd = m_database.Connection.CreateCommand();
cmd.CommandText = """
drop table if exists column_schema_table2;
drop table if exists column_schema_table1;
create table column_schema_table1(id int not null primary key);
create table column_schema_table2(id int not null primary key,
table1_id1 int not null,
table1_id2 int not null,
foreign key (table1_id1) references column_schema_table1(id),
foreign key (table1_id2) references column_schema_table1(id));
insert into column_schema_table1(id) values(1),(2);
insert into column_schema_table2(id, table1_id1, table1_id2) values(3, 1, 2);
""";
cmd.ExecuteNonQuery();

cmd.CommandText = """
select t2.id as id2, t1a.id as ida, t1b.id as idb
from column_schema_table2 t2
join column_schema_table1 t1a on t2.table1_id1 = t1a.id
join column_schema_table1 t1b on t2.table1_id2 = t1b.id;
""";
using var reader = cmd.ExecuteReader();
Assert.True(reader.Read());
var schema = reader.GetColumnSchema();
Assert.Equal(3, schema.Count);
Assert.Equal("id2", schema[0].ColumnName);
Assert.Equal("ida", schema[1].ColumnName);
Assert.Equal("idb", schema[2].ColumnName);
Assert.Equal("id", schema[0].BaseColumnName);
Assert.Equal("id", schema[1].BaseColumnName);
Assert.Equal("id", schema[2].BaseColumnName);
Assert.Equal("column_schema_table2", schema[0].BaseTableName);
Assert.Equal("column_schema_table1", schema[1].BaseTableName);
Assert.Equal("column_schema_table1", schema[2].BaseTableName);
Assert.Equal("t2", ((MySqlDbColumn) schema[0]).TableName);
Assert.Equal("t1a", ((MySqlDbColumn) schema[1]).TableName);
Assert.Equal("t1b", ((MySqlDbColumn) schema[2]).TableName);
}
#endif

private void UseReaderWithoutDisposingThread(object obj)
Expand Down

0 comments on commit fb239d6

Please sign in to comment.