Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<!-- General Properties ============================================== -->
<PropertyGroup>
<AssemblyName>Microsoft.Data.SqlClient</AssemblyName>
Expand Down Expand Up @@ -230,12 +230,6 @@
<EmbeddedResource Include="Resources\ILLink.Substitutions.xml"
Condition="'$(NormalizedTargetOs)' == 'windows_nt' AND '$(TargetFramework)' != 'net462'" />

<!-- Used by SqlMetaDataFactory to construct its DataSet -->
<EmbeddedResource Include="Resources\Microsoft.Data.SqlClient.SqlMetaData.xml">
<Link>Resources\Microsoft.Data.SqlCLient.SqlMetaData.xml</Link>
<LogicalName>Microsoft.Data.SqlClient.SqlMetaData.xml</LogicalName>
</EmbeddedResource>

<!-- Base strings in English -->
<EmbeddedResource Update="Resources\Strings.resx">
<LogicalName>Microsoft.Data.SqlClient.Resources.Strings.resources</LogicalName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ internal static Exception InvalidCommandTimeout(int value, [CallerMemberName] st
#endregion

#region SqlMetaDataFactory
// TODO: Rephrase error message
internal static Exception DataTableDoesNotExist(string collectionName)
=> Argument(StringsHelper.GetString(Strings.MDF_DataTableDoesNotExist, collectionName));

Expand All @@ -1268,8 +1269,6 @@ internal static ArgumentOutOfRangeException InvalidUpdateRowSource(UpdateRowSour
internal static Exception QueryFailed(string collectionName, Exception e)
=> InvalidOperation(StringsHelper.GetString(Strings.MDF_QueryFailed, collectionName), e);

internal static Exception NoColumns() => Argument(StringsHelper.GetString(Strings.MDF_NoColumns));

internal static InvalidOperationException ConnectionRequired(string method)
=> InvalidOperation(StringsHelper.GetString(Strings.ADP_ConnectionRequired, method));

Expand All @@ -1281,14 +1280,9 @@ internal static InvalidOperationException OpenConnectionRequired(string method,
internal static Exception OpenReaderExists(Exception e, bool marsOn)
=> InvalidOperation(StringsHelper.GetString(Strings.ADP_OpenReaderExists, marsOn ? ADP.Command : ADP.Connection), e);

internal static Exception InvalidXmlInvalidValue(string collectionName, string columnName)
=> Argument(StringsHelper.GetString(Strings.MDF_InvalidXmlInvalidValue, collectionName, columnName));

internal static Exception CollectionNameIsNotUnique(string collectionName)
=> Argument(StringsHelper.GetString(Strings.MDF_CollectionNameISNotUnique, collectionName));

internal static Exception UnableToBuildCollection(string collectionName)
=> Argument(StringsHelper.GetString(Strings.MDF_UnableToBuildCollection, collectionName));

internal static Exception UndefinedCollection(string collectionName)
=> Argument(StringsHelper.GetString(Strings.MDF_UndefinedCollection, collectionName));
Expand All @@ -1298,14 +1292,6 @@ internal static Exception UndefinedCollection(string collectionName)
internal static Exception AmbiguousCollectionName(string collectionName)
=> Argument(StringsHelper.GetString(Strings.MDF_AmbiguousCollectionName, collectionName));

internal static Exception MissingRestrictionRow() => Argument(StringsHelper.GetString(Strings.MDF_MissingRestrictionRow));

internal static Exception UndefinedPopulationMechanism(string populationMechanism)
#if NETFRAMEWORK
=> Argument(StringsHelper.GetString(Strings.MDF_UndefinedPopulationMechanism, populationMechanism));
#else
=> throw new NotImplementedException();
#endif
#endregion

#region DbConnectionPool and related
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Data.Common;
using Microsoft.Data.Common.ConnectionString;
using Microsoft.Data.ProviderBase;
using Microsoft.Data.SqlClient.Connection;
using Microsoft.Data.SqlClient.ConnectionPool;
Expand Down Expand Up @@ -749,10 +747,7 @@ private static SqlMetaDataFactory CreateMetaDataFactory(DbConnectionInternal int
{
Debug.Assert(internalConnection is not null, "internalConnection may not be null.");

Stream xmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Data.SqlClient.SqlMetaData.xml");
Debug.Assert(xmlStream is not null, $"{nameof(xmlStream)} may not be null.");

return new SqlMetaDataFactory(xmlStream, internalConnection.ServerVersion);
return new SqlMetaDataFactory(internalConnection.ServerVersion);
}

private Task<DbConnectionInternal> CreateReplaceConnectionContinuation(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Data;
using System.Data.Common;
using System.Threading.Tasks;
using Microsoft.Data.Common;

#nullable enable

namespace Microsoft.Data.SqlClient;

internal sealed partial class SqlMetaDataFactory
{
/// <summary>
/// Returns <see href="https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/common-schema-collections#datasourceinformation">
/// DataSourceInformation</see> schema collection.
/// </summary>
private sealed class DataSourceInformationCollection : MetaDataCollectionBase
{
private const string CompositeIdentifierSeparatorPattern = "\\.";
private const string DataSourceProductName = "Microsoft SQL Server";
private const GroupByBehavior GroupByBehavior = GroupByBehavior.Unrelated;
private const string IdentifierPattern = @"(^\[\p{Lo}\p{Lu}\p{Ll}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Nd}@$#_]*$)|(^\[[^\]\0]|\]\]+\]$)|(^\""[^\""\0]|\""\""+\""$)";
private const IdentifierCase IdentifierCase = IdentifierCase.Insensitive;
private const bool OrderByColumnsInSelect = false;
private const string _parameterMarkerFormat = "{0}";
private const string ParameterMarkerPattern = @"@[\p{Lo}\p{Lu}\p{Ll}\p{Lm}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Lm}\p{Nd}\uff3f_@#\$]*(?=\s+|$)";
private const int ParameterNameMaxLength = 128;
private const string ParameterNamePattern = @"^[\p{Lo}\p{Lu}\p{Ll}\p{Lm}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Lm}\p{Nd}\uff3f_@#\$]*(?=\s+|$)";
private const string QuotedIdentifierPattern = "(([^\\[]|\\]\\])*)";
private const IdentifierCase QuotedIdentifierCase = IdentifierCase.Insensitive;
private const string StatementSeparatorPattern = ";";
private const string StringLiteralPattern = "'(([^']|'')*)'";
private const SupportedJoinOperators SupportedJoinOperators = SupportedJoinOperators.Inner
| SupportedJoinOperators.LeftOuter
| SupportedJoinOperators.RightOuter
| SupportedJoinOperators.FullOuter;

internal DataSourceInformationCollection()
: base(DbMetaDataCollectionNames.DataSourceInformation, 0, 0)
{
}

public override ValueTask<DataTable> GetMetadata(MetaDataContext context, DataTable? accumulator = null)
{
if (!ADP.IsEmptyArray(context.RestrictionValues))
{
throw ADP.TooManyRestrictions(CollectionName);
}

DataTable table = accumulator ?? new(DbMetaDataCollectionNames.DataSourceInformation)
{
Columns =
{
new DataColumn(DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern, typeof(string)),
new DataColumn(DbMetaDataColumnNames.DataSourceProductName, typeof(string)),
new DataColumn(DbMetaDataColumnNames.DataSourceProductVersion, typeof(string)),
new DataColumn(DbMetaDataColumnNames.DataSourceProductVersionNormalized, typeof(string)),
new DataColumn(DbMetaDataColumnNames.GroupByBehavior, typeof(GroupByBehavior)),
new DataColumn(DbMetaDataColumnNames.IdentifierPattern, typeof(string)),
new DataColumn(DbMetaDataColumnNames.IdentifierCase, typeof(IdentifierCase)),
new DataColumn(DbMetaDataColumnNames.OrderByColumnsInSelect, typeof(bool)),
new DataColumn(DbMetaDataColumnNames.ParameterMarkerFormat, typeof(string)),
new DataColumn(DbMetaDataColumnNames.ParameterMarkerPattern, typeof(string)),
new DataColumn(DbMetaDataColumnNames.ParameterNameMaxLength, typeof(int)),
new DataColumn(DbMetaDataColumnNames.ParameterNamePattern, typeof(string)),
new DataColumn(DbMetaDataColumnNames.QuotedIdentifierPattern, typeof(string)),
new DataColumn(DbMetaDataColumnNames.QuotedIdentifierCase, typeof(IdentifierCase)),
new DataColumn(DbMetaDataColumnNames.StatementSeparatorPattern, typeof(string)),
new DataColumn(DbMetaDataColumnNames.StringLiteralPattern, typeof(string)),
new DataColumn(DbMetaDataColumnNames.SupportedJoinOperators, typeof(SupportedJoinOperators))
}
};

table.Rows.Add([
CompositeIdentifierSeparatorPattern,
DataSourceProductName,
context.ServerVersion,
context.ServerVersion,
GroupByBehavior,
IdentifierPattern,
IdentifierCase,
OrderByColumnsInSelect,
_parameterMarkerFormat,
ParameterMarkerPattern,
ParameterNameMaxLength,
ParameterNamePattern,
QuotedIdentifierPattern,
QuotedIdentifierCase,
StatementSeparatorPattern,
StringLiteralPattern,
SupportedJoinOperators
]);

return new ValueTask<DataTable>(table);
}
}
}
Loading
Loading