From 5b536cb4553073852db3637ad9c46c067dce8c32 Mon Sep 17 00:00:00 2001
From: Edward Neal <55035479+edwardneal@users.noreply.github.com>
Date: Sun, 25 Feb 2024 18:22:36 +0000
Subject: [PATCH 1/3] Merged SqlClientFactory.cs
In the process, this implements CreateDataSourceEnumerator in .NET, linking it to the newly-added SqlDataSourceEnumerator class. In .NET Framework, it also needs to implement CreatePermission and the IServiceProvider interface.
---
.../netcore/ref/Microsoft.Data.SqlClient.cs | 32 +++---
.../src/Microsoft.Data.SqlClient.csproj | 7 +-
.../SqlClient/SqlClientFactory.NetCoreApp.cs | 20 ----
.../Data/SqlClient/SqlClientFactory.cs | 55 -----------
.../netfx/src/Microsoft.Data.SqlClient.csproj | 5 +-
.../Data/SqlClient/SqlClientFactory.cs | 98 -------------------
.../Data/SqlClient/SqlClientFactory.netfx.cs | 32 ++++++
.../Data/SqlClient/SqlClientFactory.cs | 88 +++++++++++++++++
8 files changed, 148 insertions(+), 189 deletions(-)
delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.NetCoreApp.cs
delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
create mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.netfx.cs
create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs
index b114fc57b1..50b5788695 100644
--- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs
+++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs
@@ -189,23 +189,23 @@ public class SqlAuthenticationParameters
///
protected SqlAuthenticationParameters(Microsoft.Data.SqlClient.SqlAuthenticationMethod authenticationMethod, string serverName, string databaseName, string resource, string authority, string userId, string password, System.Guid connectionId, int connectionTimeout) { }
///
- public Microsoft.Data.SqlClient.SqlAuthenticationMethod AuthenticationMethod { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public Microsoft.Data.SqlClient.SqlAuthenticationMethod AuthenticationMethod { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public string Authority { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public string Authority { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public System.Guid ConnectionId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public System.Guid ConnectionId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public string DatabaseName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public string DatabaseName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public string Password { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public string Password { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public string Resource { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public string Resource { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public string ServerName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public string ServerName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public string UserId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public string UserId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public int ConnectionTimeout { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public int ConnectionTimeout { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
}
///
public abstract partial class SqlAuthenticationProvider
@@ -231,9 +231,9 @@ public partial class SqlAuthenticationToken
///
public SqlAuthenticationToken(string accessToken, System.DateTimeOffset expiresOn) { }
///
- public string AccessToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public string AccessToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
///
- public System.DateTimeOffset ExpiresOn { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
+ public System.DateTimeOffset ExpiresOn { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
}
///
public sealed partial class SqlBulkCopy : System.IDisposable
@@ -428,6 +428,16 @@ internal SqlClientFactory() { }
public override System.Data.Common.DbDataAdapter CreateDataAdapter() { throw null; }
///
public override System.Data.Common.DbParameter CreateParameter() { throw null; }
+ ///
+ public override System.Data.Common.DbDataSourceEnumerator CreateDataSourceEnumerator() { throw null; }
+#if NET6_0_OR_GREATER
+ ///
+ public override bool CanCreateBatch { get { throw null; } }
+ ///
+ public override System.Data.Common.DbBatch CreateBatch() { throw null; }
+ ///
+ public override System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; }
+#endif
}
///
public partial class SqlClientLogger
diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
index 7a3a8e208f..cd09233421 100644
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
@@ -321,6 +321,9 @@
Microsoft\Data\SqlClient\SqlClientEventSource.cs
+
+ Microsoft\Data\SqlClient\SqlClientFactory.cs
+
Microsoft\Data\SqlClient\SqlClientLogger.cs
@@ -650,7 +653,6 @@
-
@@ -971,9 +973,6 @@
Common\System\Net\Security\NegotiateStreamPal.Unix.cs
-
-
-
Microsoft\Data\SqlClient\SqlBatchCommand.Net8OrGreater.cs
diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.NetCoreApp.cs
deleted file mode 100644
index 4b0d4a8b2d..0000000000
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.NetCoreApp.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// 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.Common;
-
-namespace Microsoft.Data.SqlClient
-{
- public sealed partial class SqlClientFactory : DbProviderFactory
- {
- ///
- public override bool CanCreateBatch => true;
-
- ///
- public override DbBatch CreateBatch() => new SqlBatch();
-
- ///
- public override DbBatchCommand CreateBatchCommand() => new SqlBatchCommand();
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
deleted file mode 100644
index 2dd3261fe6..0000000000
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-// 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.Common;
-
-namespace Microsoft.Data.SqlClient
-{
- ///
- public sealed partial class SqlClientFactory : DbProviderFactory
- {
- ///
- public static readonly SqlClientFactory Instance = new SqlClientFactory();
-
- private SqlClientFactory()
- {
- }
-
- ///
- public override DbCommand CreateCommand()
- {
- return new SqlCommand();
- }
-
- ///
- public override DbCommandBuilder CreateCommandBuilder()
- {
- return new SqlCommandBuilder();
- }
-
- ///
- public override DbConnection CreateConnection()
- {
- return new SqlConnection();
- }
-
- ///
- public override DbConnectionStringBuilder CreateConnectionStringBuilder()
- {
- return new SqlConnectionStringBuilder();
- }
-
- ///
- public override DbDataAdapter CreateDataAdapter()
- {
- return new SqlDataAdapter();
- }
-
- ///
- public override DbParameter CreateParameter()
- {
- return new SqlParameter();
- }
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
index 97feee8bef..424e3a9768 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
@@ -409,6 +409,9 @@
Microsoft\Data\SqlClient\SqlClientEventSource.cs
+
+ Microsoft\Data\SqlClient\SqlClientFactory.cs
+
Microsoft\Data\SqlClient\SqlClientLogger.cs
@@ -652,7 +655,7 @@
-
+
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
deleted file mode 100644
index 3d44d202c0..0000000000
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-// 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;
-using System.Data.Common;
-using System.Data.Sql;
-using System.Security;
-using System.Security.Permissions;
-using Microsoft.Data.Common;
-
-namespace Microsoft.Data.SqlClient
-{
- ///
- public sealed class SqlClientFactory : DbProviderFactory, IServiceProvider
- {
-
- ///
- public static readonly SqlClientFactory Instance = new SqlClientFactory();
-
- private SqlClientFactory()
- {
- }
-
- ///
- public override bool CanCreateDataSourceEnumerator
- {
- get
- {
- return true;
- }
- }
-
- ///
- public override DbCommand CreateCommand()
- {
- return new SqlCommand();
- }
-
- ///
- public override DbCommandBuilder CreateCommandBuilder()
- {
- return new SqlCommandBuilder();
- }
-
- ///
- public override DbConnection CreateConnection()
- {
- return new SqlConnection();
- }
-
- ///
- public override DbConnectionStringBuilder CreateConnectionStringBuilder()
- {
- return new SqlConnectionStringBuilder();
- }
-
- ///
- public override DbDataAdapter CreateDataAdapter()
- {
- return new SqlDataAdapter();
- }
-
- ///
- public override DbParameter CreateParameter()
- {
- return new SqlParameter();
- }
-
- ///
- public override CodeAccessPermission CreatePermission(PermissionState state)
- {
- return new SqlClientPermission(state);
- }
-
- ///
- public override DbDataSourceEnumerator CreateDataSourceEnumerator()
- {
- return SqlDataSourceEnumerator.Instance;
- }
-
- ///
- /// Extension mechanism for additional services; currently the only service
- /// supported is the DbProviderServices
- ///
- /// requested service provider or null.
- object IServiceProvider.GetService(Type serviceType)
- {
- object result = null;
- if (serviceType == GreenMethods.SystemDataCommonDbProviderServices_Type)
- {
- result = GreenMethods.MicrosoftDataSqlClientSqlProviderServices_Instance();
- }
- return result;
- }
- }
-}
-
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.netfx.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.netfx.cs
new file mode 100644
index 0000000000..c6638b165b
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.netfx.cs
@@ -0,0 +1,32 @@
+// 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;
+using System.Data.Common;
+using System.Data.Sql;
+using System.Security;
+using System.Security.Permissions;
+using Microsoft.Data.Common;
+
+namespace Microsoft.Data.SqlClient
+{
+ ///
+ public sealed partial class SqlClientFactory : IServiceProvider
+ {
+ ///
+ /// Extension mechanism for additional services; currently the only service
+ /// supported is the DbProviderServices
+ ///
+ /// requested service provider or null.
+ object IServiceProvider.GetService(Type serviceType)
+ {
+ object result = null;
+ if (serviceType == GreenMethods.SystemDataCommonDbProviderServices_Type)
+ {
+ result = GreenMethods.MicrosoftDataSqlClientSqlProviderServices_Instance();
+ }
+ return result;
+ }
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
new file mode 100644
index 0000000000..244d685fdb
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
@@ -0,0 +1,88 @@
+// 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 Microsoft.Data.Sql;
+using System.Data.Common;
+using System.Security.Permissions;
+using System.Security;
+
+namespace Microsoft.Data.SqlClient
+{
+ ///
+ public sealed partial class SqlClientFactory : DbProviderFactory
+ {
+
+ ///
+ public static readonly SqlClientFactory Instance = new SqlClientFactory();
+
+ private SqlClientFactory()
+ {
+ }
+
+ ///
+ public override bool CanCreateDataSourceEnumerator => true;
+
+ ///
+ public override DbCommand CreateCommand()
+ {
+ return new SqlCommand();
+ }
+
+ ///
+ public override DbCommandBuilder CreateCommandBuilder()
+ {
+ return new SqlCommandBuilder();
+ }
+
+ ///
+ public override DbConnection CreateConnection()
+ {
+ return new SqlConnection();
+ }
+
+ ///
+ public override DbConnectionStringBuilder CreateConnectionStringBuilder()
+ {
+ return new SqlConnectionStringBuilder();
+ }
+
+ ///
+ public override DbDataAdapter CreateDataAdapter()
+ {
+ return new SqlDataAdapter();
+ }
+
+ ///
+ public override DbParameter CreateParameter()
+ {
+ return new SqlParameter();
+ }
+
+#if NETFRAMEWORK
+ ///
+ public override CodeAccessPermission CreatePermission(PermissionState state)
+ {
+ return new SqlClientPermission(state);
+ }
+#endif
+
+ ///
+ public override DbDataSourceEnumerator CreateDataSourceEnumerator()
+ {
+ return SqlDataSourceEnumerator.Instance;
+ }
+
+#if NET6_0_OR_GREATER
+ ///
+ public override bool CanCreateBatch => true;
+
+ ///
+ public override DbBatch CreateBatch() => new SqlBatch();
+
+ ///
+ public override DbBatchCommand CreateBatchCommand() => new SqlBatchCommand();
+#endif
+
+ }
+}
From d0ec486d8cdeded821bff252b68d153f4ba8bafa Mon Sep 17 00:00:00 2001
From: Edward Neal <55035479+edwardneal@users.noreply.github.com>
Date: Sun, 25 Feb 2024 19:14:07 +0000
Subject: [PATCH 2/3] Corrected out-of-date SqlClientFactoryTest
Widened test coverage (slightly) to encompass the new CreateDataSourceEnumerator functionality. Changed FactoryMethodTest to account for the fact that this returns a singleton.
---
.../FunctionalTests/SqlClientFactoryTest.cs | 36 ++++++++-----------
1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs
index f0e8d39173..b88ae0a260 100644
--- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs
@@ -21,40 +21,34 @@ public void InstanceTest()
public static readonly object[][] FactoryMethodTestData =
{
- new object[] { new Func