Skip to content

Commit d2abfc0

Browse files
authored
Add support for DataSourceInformation Schema (#795)
Some progress on the #375 issue.
1 parent 20becbb commit d2abfc0

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/MySqlConnector/Core/SchemaProvider.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Data;
5+
using System.Data.Common;
56
using System.Linq;
67
using MySql.Data.MySqlClient;
78

@@ -14,6 +15,7 @@ public SchemaProvider(MySqlConnection connection)
1415
m_connection = connection;
1516
m_schemaCollections = new Dictionary<string, Action<DataTable>>
1617
{
18+
{ "DataSourceInformation", FillDataSourceInformation},
1719
{ "MetaDataCollections", FillMetadataCollections },
1820
{ "CharacterSets", FillCharacterSets },
1921
{ "Collations", FillCollations },
@@ -58,6 +60,55 @@ public DataTable GetSchema(string collectionName)
5860
return dataTable;
5961
}
6062

63+
private void FillDataSourceInformation(DataTable dataTable)
64+
{
65+
dataTable.Columns.AddRange(new [] {
66+
new DataColumn("CompositeIdentifierSeparatorPattern", typeof(string)),
67+
new DataColumn("DataSourceProductName", typeof(string)),
68+
new DataColumn("DataSourceProductVersion", typeof(string)),
69+
new DataColumn("DataSourceProductVersionNormalized", typeof(string)),
70+
new DataColumn("GroupByBehavior", typeof(GroupByBehavior)),
71+
new DataColumn("IdentifierPattern", typeof(string)),
72+
new DataColumn("IdentifierCase", typeof(IdentifierCase)),
73+
new DataColumn("OrderByColumnsInSelect", typeof(bool)),
74+
new DataColumn("ParameterMarkerFormat", typeof(string)),
75+
new DataColumn("ParameterMarkerPattern", typeof(string)),
76+
new DataColumn("ParameterNameMaxLength", typeof(int)),
77+
new DataColumn("QuotedIdentifierPattern", typeof(string)),
78+
new DataColumn("QuotedIdentifierCase", typeof(IdentifierCase)),
79+
new DataColumn("ParameterNamePattern", typeof(string)),
80+
new DataColumn("StatementSeparatorPattern", typeof(string)),
81+
new DataColumn("StringLiteralPattern", typeof(string)),
82+
new DataColumn("SupportedJoinOperators", typeof(SupportedJoinOperators))
83+
});
84+
85+
var row = dataTable.NewRow();
86+
row["CompositeIdentifierSeparatorPattern"] = @"\.";
87+
row["DataSourceProductName"] = "MySQL";
88+
row["DataSourceProductVersion"] = m_connection.ServerVersion;
89+
row["DataSourceProductVersionNormalized"] = GetVersion(m_connection.Session.ServerVersion.Version);
90+
row["GroupByBehavior"] = GroupByBehavior.Unrelated;
91+
row["IdentifierPattern"] = @"(^\[\p{Lo}\p{Lu}\p{Ll}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Nd}@$#_]*$)|(^\[[^\]\0]|\]\]+\]$)|(^\""[^\""\0]|\""\""+\""$)";
92+
row["IdentifierCase"] = IdentifierCase.Insensitive;
93+
row["OrderByColumnsInSelect"] = false;
94+
row["ParameterMarkerFormat"] = @"{0}";
95+
row["ParameterMarkerPattern"] = @"(@[A-Za-z0-9_$#]*)";
96+
row["ParameterNameMaxLength"] = 128; // For function out parameters
97+
row["QuotedIdentifierPattern"] = @"(([^\`]|\`\`)*)";
98+
row["QuotedIdentifierCase"] = IdentifierCase.Sensitive;
99+
row["ParameterNamePattern"] = @"^[\p{Lo}\p{Lu}\p{Ll}\p{Lm}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Lm}\p{Nd}\uff3f_@#\$]*(?=\s+|$)";
100+
row["StatementSeparatorPattern"] = ";";
101+
row["StringLiteralPattern"] = @"'(([^']|'')*)'";
102+
row["SupportedJoinOperators"] =
103+
SupportedJoinOperators.FullOuter |
104+
SupportedJoinOperators.Inner |
105+
SupportedJoinOperators.LeftOuter |
106+
SupportedJoinOperators.RightOuter;
107+
dataTable.Rows.Add(row);
108+
}
109+
110+
private string GetVersion(Version v) => $"{v.Major:00}.{v.Minor:00}.{v.Build:0000}";
111+
61112
private void FillMetadataCollections(DataTable dataTable)
62113
{
63114
dataTable.Columns.AddRange(new[] {

tests/SideBySide/ConnectionTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Data;
3+
using System.Data.Common;
34
using Dapper;
45
using MySql.Data.MySqlClient;
56
using Xunit;
@@ -241,6 +242,17 @@ public void CloneWithCopiesExistingPassword()
241242
connection2.Open();
242243
Assert.Equal(ConnectionState.Open, connection2.State);
243244
}
245+
#endif
246+
#if !NETCOREAPP1_1_2
247+
[Fact]
248+
public void GetDataSourceInformationSchemaCollection()
249+
{
250+
using var connection = new MySqlConnection(AppConfig.ConnectionString);
251+
connection.Open();
252+
253+
var dataTable = connection.GetSchema(DbMetaDataCollectionNames.DataSourceInformation);
254+
Assert.Equal(connection.ServerVersion, dataTable.Rows[0]["DataSourceProductVersion"]);
255+
}
244256
#endif
245257
}
246258
}

0 commit comments

Comments
 (0)