Skip to content

Commit f697ee7

Browse files
committed
fix(spanner): implement common schema collections
1 parent d7344fc commit f697ee7

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎apis/Google.Cloud.Spanner.Data/Google.Cloud.Spanner.Data.Tests/SpannerConnectionTests.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public void GetSchema_ExposesCommonCollections()
3737
foreach (var name in new[] { "MetaDataCollections", "DataSourceInformation", "DataTypes", "Restrictions", "ReservedWords" })
3838
{
3939
Assert.Equal(name, connection.GetSchema(name).TableName);
40+
Assert.Equal(name, connection.GetSchema(name.ToUpperInvariant()).TableName);
4041
}
42+
var exception = Assert.Throws<ArgumentException>(() => connection.GetSchema("DataTypes", new[] { "restriction" }));
43+
Assert.Equal("restrictionValues", exception.ParamName);
4144
}
4245

4346
[Fact]

‎apis/Google.Cloud.Spanner.Data/Google.Cloud.Spanner.Data/SpannerConnection.cs‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ public override string ConnectionString
109109
public override DataTable GetSchema(string collectionName, string[] restrictionValues)
110110
{
111111
GaxPreconditions.CheckNotNullOrEmpty(collectionName, nameof(collectionName));
112-
switch (collectionName)
112+
if (restrictionValues != null && restrictionValues.Length != 0)
113113
{
114-
case "MetaDataCollections":
114+
throw new ArgumentException("Restrictions are not supported for the requested schema collection.", nameof(restrictionValues));
115+
}
116+
switch (collectionName.ToUpperInvariant())
117+
{
118+
case "METADATACOLLECTIONS":
115119
var collections = CreateSchemaTable(collectionName,
116120
("CollectionName", typeof(string)),
117121
("NumberOfRestrictions", typeof(int)),
@@ -121,7 +125,7 @@ public override DataTable GetSchema(string collectionName, string[] restrictionV
121125
collections.Rows.Add(name, 0, 0);
122126
}
123127
return collections;
124-
case "DataSourceInformation":
128+
case "DATASOURCEINFORMATION":
125129
return CreateSchemaTable(collectionName,
126130
("CompositeIdentifierSeparatorPattern", typeof(string)),
127131
("DataSourceProductName", typeof(string)),
@@ -139,7 +143,7 @@ public override DataTable GetSchema(string collectionName, string[] restrictionV
139143
("StatementSeparatorPattern", typeof(string)),
140144
("StringLiteralPattern", typeof(string)),
141145
("SupportedJoinOperators", typeof(int)));
142-
case "DataTypes":
146+
case "DATATYPES":
143147
return CreateSchemaTable(collectionName,
144148
("TypeName", typeof(string)), ("ProviderDbType", typeof(int)), ("ColumnSize", typeof(long)),
145149
("CreateFormat", typeof(string)), ("CreateParameters", typeof(string)), ("DataType", typeof(string)),
@@ -149,11 +153,11 @@ public override DataTable GetSchema(string collectionName, string[] restrictionV
149153
("IsUnsigned", typeof(bool)), ("MaximumScale", typeof(short)), ("MinimumScale", typeof(short)),
150154
("IsConcurrencyType", typeof(bool)), ("IsLiteralSupported", typeof(bool)),
151155
("LiteralPrefix", typeof(string)), ("LiteralSuffix", typeof(string)));
152-
case "Restrictions":
156+
case "RESTRICTIONS":
153157
return CreateSchemaTable(collectionName,
154158
("CollectionName", typeof(string)), ("RestrictionName", typeof(string)),
155159
("RestrictionDefault", typeof(string)), ("RestrictionNumber", typeof(int)));
156-
case "ReservedWords":
160+
case "RESERVEDWORDS":
157161
return CreateSchemaTable(collectionName, ("ReservedWord", typeof(string)));
158162
default:
159163
throw new ArgumentException($"The schema collection '{collectionName}' is not supported.", nameof(collectionName));

0 commit comments

Comments
 (0)