edit/createRow Default Values (#266)

Returns strings for the default value of a column when a new row is created. The values that could come back:
* `null` when there isn't a default for the column
* a string when there is a default for the column
* a placeholder (currently <TBD>) when the column cannot be updated

* Renaming EditTableMetadata to reflect its SMO source

* Implementation of returning default values

* Unit test for default values

* Reworking column defaults using default constraints

* Adding unit test for new sql script unwrapper

* Disabling flaky test

* Fixing oddities in tests, removing personal tests

* Fixing broken unit test
This commit is contained in:
Benjamin Russell
2017-03-08 13:51:38 -08:00
committed by GitHub
parent 29d27c2341
commit 056a08cd1b
21 changed files with 286 additions and 90 deletions

View File

@@ -5,6 +5,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.Common;
using System.IO;
using System.Linq;
@@ -96,7 +97,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
/// </summary>
/// <exception cref="InvalidOperationException">If inserting into cache fails</exception>
/// <returns>The internal ID of the newly created row</returns>
public long CreateRow()
public EditCreateRowResult CreateRow()
{
// Create a new row ID (atomically, since this could be accesses concurrently)
long newRowId = NextRowId++;
@@ -110,7 +111,33 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
throw new InvalidOperationException(SR.EditDataFailedAddRow);
}
return newRowId;
// Set the default values of the row if we know them
string[] defaultValues = new string[objectMetadata.Columns.Count];
for(int i = 0; i < objectMetadata.Columns.Count; i++)
{
EditColumnWrapper col = objectMetadata.Columns[i];
// If the column is calculated, return the calculated placeholder as the display value
if (col.IsCalculated)
{
defaultValues[i] = SR.EditDataComputedColumnPlaceholder;
}
else
{
if (col.DefaultValue != null)
{
newRow.SetCell(i, col.DefaultValue);
}
defaultValues[i] = col.DefaultValue;
}
}
EditCreateRowResult output = new EditCreateRowResult
{
NewRowId = newRowId,
DefaultValues = defaultValues
};
return output;
}
/// <summary>