mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-10 18:22:36 -05:00
Convert Async to sync (SqlClient apis) and cleanup async usage (#2167)
This commit is contained in:
@@ -528,10 +528,10 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
{
|
||||
// Get the command from the edit operation and execute it
|
||||
using (DbCommand editCommand = editOperation.GetCommand(connection))
|
||||
using (DbDataReader reader = await editCommand.ExecuteReaderAsync())
|
||||
using (DbDataReader reader = editCommand.ExecuteReader())
|
||||
{
|
||||
// Apply the changes of the command to the result set
|
||||
await editOperation.ApplyChanges(reader);
|
||||
editOperation.ApplyChanges(reader);
|
||||
}
|
||||
}
|
||||
catch (EditDataDeleteException)
|
||||
|
||||
@@ -12,7 +12,6 @@ using System.Data.Common;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
@@ -74,11 +73,11 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// Reader returned from the execution of the command to insert a new row. Should contain
|
||||
/// a single row that represents the newly added row.
|
||||
/// </param>
|
||||
public override Task ApplyChanges(DbDataReader dataReader)
|
||||
public override void ApplyChanges(DbDataReader dataReader)
|
||||
{
|
||||
Validate.IsNotNull(nameof(dataReader), dataReader);
|
||||
|
||||
return AssociatedResultSet.AddRow(dataReader);
|
||||
AssociatedResultSet.AddRow(dataReader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -9,7 +9,6 @@ using System;
|
||||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
@@ -71,11 +70,10 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// Reader returned from the execution of the command to insert a new row. Should NOT
|
||||
/// contain any rows.
|
||||
/// </param>
|
||||
public override Task ApplyChanges(DbDataReader dataReader)
|
||||
public override void ApplyChanges(DbDataReader dataReader)
|
||||
{
|
||||
// Take the result set and remove the row from it
|
||||
AssociatedResultSet.RemoveRow(RowId);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,7 +10,6 @@ using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
@@ -86,7 +85,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// <param name="dataReader">
|
||||
/// Data reader from execution of the command to commit the change to the db
|
||||
/// </param>
|
||||
public abstract Task ApplyChanges(DbDataReader dataReader);
|
||||
public abstract void ApplyChanges(DbDataReader dataReader);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a command that will commit the change to the db
|
||||
|
||||
@@ -14,7 +14,6 @@ using Microsoft.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
@@ -74,10 +73,10 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// Reader returned from the execution of the command to update a row. Should contain
|
||||
/// a single row that represents all the values of the row.
|
||||
/// </param>
|
||||
public override Task ApplyChanges(DbDataReader dataReader)
|
||||
public override void ApplyChanges(DbDataReader dataReader)
|
||||
{
|
||||
Validate.IsNotNull(nameof(dataReader), dataReader);
|
||||
return AssociatedResultSet.UpdateRow(RowId, dataReader);
|
||||
AssociatedResultSet.UpdateRow(RowId, dataReader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -12,8 +12,6 @@ using System.Data.SqlTypes;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
@@ -83,17 +81,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
|
||||
#region DbDataReader Methods
|
||||
|
||||
/// <summary>
|
||||
/// Pass-through to DbDataReader.ReadAsync()
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token to use for cancelling a query</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("Deprecated due to performance issues, please use Read() instead.")]
|
||||
public Task<bool> ReadAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return DbDataReader.ReadAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pass-through to DbDataReader.Read()
|
||||
///
|
||||
|
||||
@@ -449,10 +449,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// Adds a new row to the result set by reading the row from the provided db data reader
|
||||
/// </summary>
|
||||
/// <param name="dbDataReader">The result of a command to insert a new row should be UNREAD</param>
|
||||
public async Task AddRow(DbDataReader dbDataReader)
|
||||
public void AddRow(DbDataReader dbDataReader)
|
||||
{
|
||||
// Write the new row to the end of the file
|
||||
long newOffset = await AppendRowToBuffer(dbDataReader);
|
||||
long newOffset = AppendRowToBuffer(dbDataReader);
|
||||
|
||||
// Add the row to file offset list
|
||||
fileOffsets.Add(newOffset);
|
||||
@@ -464,10 +464,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// <param name="rowId"></param>
|
||||
/// <param name="dbDataReader"></param>
|
||||
/// <returns></returns>
|
||||
public async Task UpdateRow(long rowId, DbDataReader dbDataReader)
|
||||
public void UpdateRow(long rowId, DbDataReader dbDataReader)
|
||||
{
|
||||
// Write the updated row to the end of the file
|
||||
long newOffset = await AppendRowToBuffer(dbDataReader);
|
||||
long newOffset = AppendRowToBuffer(dbDataReader);
|
||||
|
||||
// Update the file offset of the row in question
|
||||
fileOffsets[rowId] = newOffset;
|
||||
@@ -782,7 +782,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// </summary>
|
||||
/// <param name="dbDataReader">An UNREAD db data reader</param>
|
||||
/// <returns>The offset into the file where the row was inserted</returns>
|
||||
private async Task<long> AppendRowToBuffer(DbDataReader dbDataReader)
|
||||
private long AppendRowToBuffer(DbDataReader dbDataReader)
|
||||
{
|
||||
Validate.IsNotNull(nameof(dbDataReader), dbDataReader);
|
||||
// Sanity check to make sure that results read has started
|
||||
@@ -793,11 +793,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
// NOTE: We are no longer checking to see if the data reader has rows before reading
|
||||
// b/c of a quirk in SqlClient. In some scenarios, a SqlException isn't thrown until we
|
||||
// read. In order to get appropriate errors back to the user, we'll read first.
|
||||
// Returning false from .ReadAsync means there aren't any rows.
|
||||
// Returning false from .Read means there aren't any rows.
|
||||
|
||||
// Create a storage data reader, read it, make sure there were results
|
||||
var dataReader = new StorageDataReader(dbDataReader);
|
||||
if (!await dataReader.ReadAsync(CancellationToken.None))
|
||||
if (!dataReader.Read())
|
||||
{
|
||||
throw new InvalidOperationException(SR.QueryServiceResultSetAddNoRows);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user