Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/MySqlConnector/Core/SchemaProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public SchemaProvider(MySqlConnection connection)
{ "DataTypes", FillDataTypes },
{ "Procedures", FillProcedures },
{ "ReservedWords", FillReservedWords },
{ "Restrictions", FillRestrictions },
};
}

public DataTable GetSchema() => GetSchema("MetaDataCollections");

public DataTable GetSchema(string collectionName)
public DataTable GetSchema(string collectionName, string[] restrictions = null)
{
if (!m_schemaCollections.TryGetValue(collectionName, out var fillAction))
throw new ArgumentException("Invalid collection name.", nameof(collectionName));
Expand All @@ -33,6 +34,19 @@ public DataTable GetSchema(string collectionName)
return dataTable;
}

private void FillRestrictions(DataTable dataTable)
{
dataTable.Columns.AddRange(new[] {
new DataColumn("CollectionName", typeof(string)),
new DataColumn("RestrictionName", typeof(string)),
new DataColumn("RestrictionDefault", typeof(string)),
new DataColumn("RestrictionNumber", typeof(int))
});

foreach (var collectionName in m_schemaCollections.Keys)
dataTable.Rows.Add(collectionName, 0, 0);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Restrictions schema should have four columns: CollectionName, RestrictionName, RestrictionDefault, RestrictionNumber: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/common-schema-collections#restrictions

This table is filled with the names of restrictions that are supported by other schema tables.

For example, to indicate three restrictions on the Tables schema, you would add these rows:

CollectionName RestrictionName RestrictionDefault RestrictionNumber
Tables Schema   1
Tables Table   2
Tables TableType   3

While it's not OK to bring code from Connector/NET into this project, it is totally fine to perform "black box" testing and see what (for example) connection.GetSchema("Restrictions") returns when executed against that library. This code should return a subset of what it supports.


private void FillMetadataCollections(DataTable dataTable)
{
dataTable.Columns.AddRange(new[] {
Expand All @@ -41,8 +55,11 @@ private void FillMetadataCollections(DataTable dataTable)
new DataColumn("NumberOfIdentifierParts", typeof(int))
});

foreach (var collectionName in m_schemaCollections.Keys)
dataTable.Rows.Add(collectionName, 0, 0);
foreach (var collectionName in m_schemaCollections.Keys) {
dataTable.Rows.Add(collectionName, "Schema", string.Empty, 1);
dataTable.Rows.Add(collectionName, "Table", string.Empty, 2);
dataTable.Rows.Add(collectionName, "TableType", string.Empty, 3);
}
}

private void FillDataTypes(DataTable dataTable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private static async Task ClearPoolAsync(MySqlConnection connection, IOBehavior
public override DataTable GetSchema(string collectionName) => GetSchemaProvider().GetSchema(collectionName);

/// <inheritdoc cref="DbConnection.GetSchema(string)"/>
public override DataTable GetSchema(string collectionName, string[] restrictions) => GetSchemaProvider().GetSchema(collectionName);
public override DataTable GetSchema(string collectionName, string[] restrictions) => GetSchemaProvider().GetSchema(collectionName, restrictions);

private SchemaProvider GetSchemaProvider()
{
Expand Down
16 changes: 14 additions & 2 deletions tests/SideBySide/QueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public async Task MultipleReaders()
}
}
}

[Fact]
public async Task UndisposedReader()
{
Expand Down Expand Up @@ -573,7 +573,7 @@ public void DapperNullableBoolNullFirst()
Assert.True(rows[1].IsBold);
Assert.Null(rows[2].IsBold);
}

[SkippableFact(Baseline = "https://bugs.mysql.com/bug.php?id=78760")]
public void TabsAndNewLines()
{
Expand Down Expand Up @@ -1156,6 +1156,18 @@ public void ReservedWordsSchema()
Assert.Contains("CREATE", table.Rows.Cast<DataRow>().Select(x => (string) x[0]));
#endif
}

[Fact]
public void RestrictionsSchema()
{
var table = m_database.Connection.GetSchema("Restrictions");
Assert.NotNull(table);
Assert.Equal(4, table.Columns.Count);
Assert.Equal("CollectionName", table.Columns[0].ColumnName);
Assert.Equal("RestrictionName", table.Columns[1].ColumnName);
Assert.Equal("RestrictionDefault", table.Columns[2].ColumnName);
Assert.Equal("RestrictionNumber", table.Columns[3].ColumnName);
}
#endif

class BoolTest
Expand Down