-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement MySqlConnection.GetSchema #361
Comments
The It's available in .NET 4.5+ and .NET Standard 2.0. In Connector/NET, This will need signficant integration testing to verify backwards compatibility with the schemas returned by Connector/NET. |
I think we can start with simple and throw NotSupportedException on runtime for collection names that are not yet implemented. It's still better than the current not-exist-anything-version. |
Moved |
After MySqlDbType fix, I think adding a method like this to /// <summary>
/// System.Data.Common, initial implementation of API DBConnection.GetSchema(String)
/// Returns schema information for the data source of this DbConnection using the specified string for the schema name.
/// </summary>
/// <param name="collectionName">Specifies the name of the schema to return.</param>
/// <returns>A DataTable that contains schema information.</returns>
public override System.Data.DataTable GetSchema(string collectionName)
{
var dt = new DataTable(collectionName);
switch (collectionName)
{
case "DataTypes":
dt.Columns.AddRange(new[] { // The names come from DbMetaDataColumnNames
new DataColumn("DataType", typeof(string)),
new DataColumn("TypeName", typeof(string)),
new DataColumn("ProviderDbType", typeof(int))
});
foreach (MySqlDbType mapItem in Enum.GetValues(typeof(MySqlDbType)))
{
// Mapping needs a bit work...:
var map = Types.TypeMapper.Mapper.GetDbTypeMapping(mapItem);
dt.Rows.Add(new object[] {
map.ClrType.Name,
Enum.GetName(typeof(MySqlDbType), map.MySqlDbType),
(int)map.DbType
});
}
// Rows result should be like:
//dt.Rows.Add(new object[] { "System.Int16", "smallint", 10 });
//dt.Rows.Add(new object[] { "System.Int32", "int", 11 });
//dt.Rows.Add(new object[] { "System.String","varchar",16 });
//dt.Rows.Add(new object[] { "System.String","nvarchar",16 });
//...
return dt;
case "Procedures":
dt.Columns.AddRange(new[] {
new DataColumn("ROUTINE_TYPE"),
new DataColumn("ROUTINE_SCHEMA"),
new DataColumn("SPECIFIC_NAME")
});
var procsQuery = "SELECT ROUTINE_TYPE, ROUTINE_SCHEMA, SPECIFIC_NAME FROM INFORMATION_SCHEMA.ROUTINES;";
if (m_connectionState != ConnectionState.Open)
{
this.Open();
}
using (var com = new MySqlCommand(procsQuery, this))
using (var reader = com.ExecuteReader())
{
while (reader.Read())
{
dt.Rows.Add(new object[] { reader.GetString(0), reader.GetString(1), reader.GetString(2) });
}
}
return dt;
default:
throw new NotImplementedException("Not yet supported: GetSchema(\"" + collectionName + "\"). Please send a PR.");
}
} |
One more column, Edit: "CreateFormat" or "IsUnsigned". I don't mind which one, either of them is ok. |
As complete GetSchema("DataTypes") seems to be pretty static and not related to database, it can be easily printed out. IMHO most of the columns are not relevant.
|
Common Schema Collections are documented here. |
Yes, probably would be a good idea to implement some level MetaDataCollections so that the users would know supported collections of MySqlConnector. |
That being said, I'm currently already very happy with the current implementation. |
The current output of |
Implemented in 0.29.0. |
I would like to use some of .NET System.Data.Common database-interface features, like:
DbConnection.GetSchema(...)
MySqlDbType
For a start, these would be nice:
GetSchema "DataTypes":
GetSchema "Procedures":
The text was updated successfully, but these errors were encountered: