-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to Microsoft.Data.SqlClient in http/worker host and Dibix.Test…
…ing [Pt. II]
- Loading branch information
1 parent
e233b73
commit 4c2a5c6
Showing
21 changed files
with
258 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#nullable enable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.Data.SqlClient.Server; | ||
|
||
namespace Dibix | ||
{ | ||
public sealed class MicrosoftSqlClientAdapter : SqlClientAdapter | ||
{ | ||
private readonly SqlConnection? _sqlConnection; | ||
|
||
public override bool IsSqlClient => _sqlConnection != null; | ||
|
||
public MicrosoftSqlClientAdapter(DbConnection connection) | ||
{ | ||
if (connection is not SqlConnection sqlConnection) | ||
return; | ||
|
||
_sqlConnection = sqlConnection; | ||
sqlConnection.InfoMessage += OnInfoMessage; | ||
} | ||
|
||
public override void DetachInfoMessageHandler() | ||
{ | ||
if (_sqlConnection != null) | ||
_sqlConnection.InfoMessage -= OnInfoMessage; | ||
} | ||
|
||
public override int? TryGetSqlExceptionNumber(Exception exception) => exception is SqlException sqlException ? sqlException.Number : null; | ||
|
||
protected override object GetStructuredTypeParameterValue(StructuredType type) | ||
{ | ||
SqlDataRecord[] records = MapRecords(type).ToArray(); | ||
return records; | ||
} | ||
|
||
protected override void SetProviderSpecificParameterProperties(IDbDataParameter parameter, SqlDbType sqlDbType, string typeName) | ||
{ | ||
if (parameter is not SqlParameter sqlParam) | ||
return; | ||
|
||
sqlParam.SqlDbType = sqlDbType; | ||
sqlParam.TypeName = typeName; | ||
} | ||
|
||
private static IEnumerable<SqlDataRecord> MapRecords(StructuredType type) | ||
{ | ||
SqlMetaData[] metadata = MapMetadata(type).ToArray(); | ||
|
||
foreach (Microsoft.SqlServer.Server.SqlDataRecord oldRecord in type.GetRecords()) | ||
{ | ||
SqlDataRecord newRecord = new SqlDataRecord(metadata); | ||
for (int i = 0; i < oldRecord.FieldCount; i++) | ||
newRecord.SetValue(i, oldRecord.GetValue(i)); | ||
|
||
yield return newRecord; | ||
} | ||
} | ||
|
||
private void OnInfoMessage(object sender, SqlInfoMessageEventArgs e) => OnInfoMessage(e.Message); | ||
|
||
private static IEnumerable<SqlMetaData> MapMetadata(StructuredType type) | ||
{ | ||
foreach (Microsoft.SqlServer.Server.SqlMetaData oldMetadata in type.GetMetadata()) | ||
{ | ||
yield return new SqlMetaData | ||
( | ||
name: oldMetadata.Name | ||
, dbType: oldMetadata.SqlDbType | ||
, maxLength: oldMetadata.MaxLength | ||
, precision: oldMetadata.Precision | ||
, scale: oldMetadata.Scale | ||
, locale: default | ||
, compareOptions: default | ||
, userDefinedType: default | ||
); | ||
} | ||
} | ||
} | ||
} | ||
#nullable restore |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.