|
|
|
|
using System.Data;
|
|
|
|
|
using Connected.Annotations;
|
|
|
|
|
using Connected.Data.Storage;
|
|
|
|
|
using Connected.ServiceModel.Client.Data.Remote;
|
|
|
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
|
|
|
|
|
|
namespace Connected.ServiceModel.Client.Data;
|
|
|
|
|
|
|
|
|
|
[ServiceRegistration(ServiceRegistrationMode.Auto, ServiceRegistrationScope.Transient)]
|
|
|
|
|
internal sealed class TableDataConnection : DatabaseConnection
|
|
|
|
|
{
|
|
|
|
|
public TableDataConnection(RemoteTableService tables, ICancellationContext context) : base(context)
|
|
|
|
|
{
|
|
|
|
|
Tables = tables;
|
|
|
|
|
}
|
|
|
|
|
private RemoteTableService Tables { get; }
|
|
|
|
|
|
|
|
|
|
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 TableConnection(Tables, ConnectionString);
|
|
|
|
|
}
|
|
|
|
|
}
|