private async Task CleanupDuplicateStatements(CancellationToken cancellationToken) { DataTable dataTable = await _commander.ExecuteSqlAsync(GetDuplicateStatementsSql, cancellationToken); if (dataTable.Rows.Count == 0) { return; } foreach (DataRow dataRow in dataTable.Rows) { string sourceLink = dataRow.GetSafeString("SourceLink"); int count = dataRow.GetSafeInt32("Count"); DataTable statementIds = await _commander.ExecuteSqlAsync($"SELECT TOP {count - 1} [StatementId] FROM [dbo].[Statement] (NOLOCK) WHERE [SourceLink] = '{sourceLink}' AND [IsLatest] = 0 ORDER BY [StatementId] DESC", cancellationToken); foreach (DataRow statementRow in statementIds.Rows) { long statementId = statementRow.GetSafeInt64("StatementId"); await _commander.ExecuteNonQueryAsync($"DELETE FROM [dbo].[Statement] WHERE [StatementId] = {statementId}", cancellationToken); } } }
public override async Task <SqlNonQueryResult> ExecuteAsync(CancellationToken cancellationToken) { return(await _databaseCommander.ExecuteNonQueryAsync((SqlNonQueryRequest)CommandRequest, cancellationToken)); }