You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.4 KiB
61 lines
1.4 KiB
using Connected.Annotations;
|
|
using Connected.Data.Storage;
|
|
using Connected.ServiceModel;
|
|
using Microsoft.Data.SqlClient;
|
|
using System.Data;
|
|
|
|
namespace Connected.Data.Sql;
|
|
|
|
[ServiceRegistration(ServiceRegistrationMode.Auto, ServiceRegistrationScope.Transient)]
|
|
internal sealed class SqlDataConnection : DatabaseConnection
|
|
{
|
|
public SqlDataConnection(ICancellationContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
protected override void SetupParameters(IStorageCommand command, IDbCommand cmd)
|
|
{
|
|
if (cmd.Parameters.Count > 0)
|
|
{
|
|
foreach (SqlParameter i in cmd.Parameters)
|
|
i.Value = DBNull.Value;
|
|
|
|
return;
|
|
}
|
|
|
|
if (command.Operation.Parameters is null)
|
|
return;
|
|
|
|
foreach (var i in command.Operation.Parameters)
|
|
{
|
|
cmd.Parameters.Add(new SqlParameter
|
|
{
|
|
ParameterName = i.Name,
|
|
DbType = i.Type,
|
|
Direction = i.Direction
|
|
});
|
|
}
|
|
}
|
|
|
|
protected override object GetParameterValue(IDbCommand command, string parameterName)
|
|
{
|
|
if (command is SqlCommand cmd)
|
|
return cmd.Parameters[parameterName].Value;
|
|
|
|
return null;
|
|
}
|
|
|
|
protected override void SetParameterValue(IDbCommand command, string parameterName, object value)
|
|
{
|
|
if (command is SqlCommand cmd)
|
|
cmd.Parameters[parameterName].Value = value;
|
|
}
|
|
|
|
protected override async Task<IDbConnection> OnCreateConnection()
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
return new SqlConnection(ConnectionString);
|
|
}
|
|
}
|