mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 01:25:40 -05:00
feature/edit/subset (#283)
* Changing query/subset API to only use Result on success, Error on error * Creating an interservice API for getting query result subsets * Updates to subset API * RowStartIndex is now long * Output of query/subset is a 2D array of DbCellValue * Adding LongSkip method to LongList to allow skipping ahead by longs * Moving LongList back to ServiceLayer utilities. Move refactoring * Stubbing out request for edit/subset * Initial implementation of getting edit rows * Unit tests for RowEdit and RowDelete .GetEditRow * Fixing major bugs in LongList implementation, adding much more thorough tests * Adding some more unit tests and fixes to make unit tests pass * Fixing comment
This commit is contained in:
@@ -85,6 +85,22 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Converts the cell update to a DbCellValue
|
||||
/// </summary>
|
||||
public DbCellValue AsDbCellValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DbCellValue
|
||||
{
|
||||
DisplayValue = ValueAsString,
|
||||
IsNull = Value == DBNull.Value,
|
||||
RawObject = Value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The column that the cell will be placed in
|
||||
/// </summary>
|
||||
|
||||
@@ -122,6 +122,26 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
return command;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a edit row that represents a row pending insertion
|
||||
/// </summary>
|
||||
/// <param name="cachedRow">Original, cached cell contents. (Should be null in this case)</param>
|
||||
/// <returns>EditRow of pending update</returns>
|
||||
public override EditRow GetEditRow(DbCellValue[] cachedRow)
|
||||
{
|
||||
// Iterate over the new cells. If they are null, generate a blank value
|
||||
DbCellValue[] editCells = newCells.Select(cell => cell == null
|
||||
? new DbCellValue {DisplayValue = string.Empty, IsNull = false, RawObject = null}
|
||||
: cell.AsDbCellValue)
|
||||
.ToArray();
|
||||
return new EditRow
|
||||
{
|
||||
Id = RowId,
|
||||
Cells = editCells,
|
||||
State = EditRow.EditRowState.DirtyInsert
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates the INSERT INTO statement that will apply the row creation
|
||||
/// </summary>
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
@@ -72,6 +73,24 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
return command;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a edit row that represents a row pending deletion. All the original cells are
|
||||
/// intact but the state is dirty.
|
||||
/// </summary>
|
||||
/// <param name="cachedRow">Original, cached cell contents</param>
|
||||
/// <returns>EditRow that is pending deletion</returns>
|
||||
public override EditRow GetEditRow(DbCellValue[] cachedRow)
|
||||
{
|
||||
Validate.IsNotNull(nameof(cachedRow), cachedRow);
|
||||
|
||||
return new EditRow
|
||||
{
|
||||
Id = RowId,
|
||||
Cells = cachedRow,
|
||||
State = EditRow.EditRowState.DirtyDelete
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a DELETE statement to delete this row
|
||||
/// </summary>
|
||||
|
||||
@@ -85,6 +85,14 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// <returns>Command to commit the change to the db</returns>
|
||||
public abstract DbCommand GetCommand(DbConnection connection);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a row that has the pending update applied. The dirty status of the row is
|
||||
/// reflected in the returned EditRow.
|
||||
/// </summary>
|
||||
/// <param name="cachedRow">The original, cached row values</param>
|
||||
/// <returns>An EditRow with the pending changes applied</returns>
|
||||
public abstract EditRow GetEditRow(DbCellValue[] cachedRow);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the row edit into a SQL statement
|
||||
/// </summary>
|
||||
|
||||
@@ -113,6 +113,30 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
return command;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a edit row that represents a row with pending update. The cells pending
|
||||
/// updates are merged into the unchanged cells.
|
||||
/// </summary>
|
||||
/// <param name="cachedRow">Original, cached cell contents</param>
|
||||
/// <returns>EditRow with pending updates</returns>
|
||||
public override EditRow GetEditRow(DbCellValue[] cachedRow)
|
||||
{
|
||||
Validate.IsNotNull(nameof(cachedRow), cachedRow);
|
||||
|
||||
// For each cell that is pending update, replace the db cell value with a new one
|
||||
foreach (var cellUpdate in cellUpdates)
|
||||
{
|
||||
cachedRow[cellUpdate.Key] = cellUpdate.Value.AsDbCellValue;
|
||||
}
|
||||
|
||||
return new EditRow
|
||||
{
|
||||
Id = RowId,
|
||||
Cells = cachedRow,
|
||||
State = EditRow.EditRowState.DirtyUpdate
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an update statement to change the associated row.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user