diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/Contracts/EditCreateRowRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/Contracts/EditCreateRowRequest.cs
index e3b3a0b9..8a24a27f 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/EditData/Contracts/EditCreateRowRequest.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/Contracts/EditCreateRowRequest.cs
@@ -19,6 +19,12 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
///
public class EditCreateRowResult
{
+ ///
+ /// Each element corresponds to the default value for the column. If null, no default is
+ /// defined. Calculated columns will have placeholders provided here.
+ ///
+ public string[] DefaultValues { get; set; }
+
///
/// The internal ID of the newly created row
///
diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/EditColumnWrapper.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/EditColumnWrapper.cs
index 28177766..b67535f3 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/EditData/EditColumnWrapper.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/EditColumnWrapper.cs
@@ -18,11 +18,23 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
///
public DbColumnWrapper DbColumn { get; set; }
+ ///
+ /// If set, this is a string representation of the default value. If set to null, then the
+ /// column does not have a default value.
+ ///
+ public string DefaultValue { get; set; }
+
///
/// Escaped identifier for the name of the column
///
public string EscapedName { get; set; }
+ ///
+ /// Whether or not the column is calculated on the server side. This could be a computed
+ /// column or a identity column.
+ ///
+ public bool IsCalculated { get; set; }
+
///
/// Whether or not the column is used in a key to uniquely identify a row
///
diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/EditDataService.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/EditDataService.cs
index 2f755021..0eeef854 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/EditData/EditDataService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/EditDataService.cs
@@ -115,15 +115,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
internal Task HandleCreateRowRequest(EditCreateRowParams createParams,
RequestContext requestContext)
{
- return HandleSessionRequest(createParams, requestContext, session =>
- {
- // Create the row and get the ID of the new row
- long newRowId = session.CreateRow();
- return new EditCreateRowResult
- {
- NewRowId = newRowId
- };
- });
+ return HandleSessionRequest(createParams, requestContext, s => s.CreateRow());
}
internal Task HandleDeleteRowRequest(EditDeleteRowParams deleteParams,
diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/EditSession.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/EditSession.cs
index d490eb07..6652f92d 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/EditData/EditSession.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/EditSession.cs
@@ -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
///
/// If inserting into cache fails
/// The internal ID of the newly created row
- 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;
}
///
diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/IEditTableMetadata.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/IEditTableMetadata.cs
index 67181ee8..9bbe3d26 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/EditData/IEditTableMetadata.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/IEditTableMetadata.cs
@@ -16,7 +16,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
///
/// All columns in the table that's being edited
///
- IEnumerable Columns { get; }
+ IReadOnlyList Columns { get; }
///
/// The escaped name of the table that's being edited
@@ -31,6 +31,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
///
/// Columns that can be used to uniquely identify the a row
///
- IEnumerable KeyColumns { get; }
+ IReadOnlyList KeyColumns { get; }
}
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs
index 696d1ceb..4a0930e3 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs
@@ -62,7 +62,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
throw new ArgumentOutOfRangeException(nameof(objectName), SR.EditDataObjectMetadataNotFound);
}
- return new EditTableMetadata(columns, result);
+ return new SmoEditTableMetadata(columns, result);
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/EditTableMetadata.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditTableMetadata.cs
similarity index 82%
rename from src/Microsoft.SqlTools.ServiceLayer/EditData/EditTableMetadata.cs
rename to src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditTableMetadata.cs
index 9f12416d..e6fa8cf0 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/EditData/EditTableMetadata.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditTableMetadata.cs
@@ -16,7 +16,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
///
/// Provides metadata about the table or view being edited
///
- public class EditTableMetadata : IEditTableMetadata
+ public class SmoEditTableMetadata : IEditTableMetadata
{
private readonly List columns;
private readonly List keyColumns;
@@ -26,7 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
///
/// DB columns from the ResultSet
/// SMO metadata object for the table/view being edited
- public EditTableMetadata(IList dbColumns, TableViewTableTypeBase smoObject)
+ public SmoEditTableMetadata(IList dbColumns, TableViewTableTypeBase smoObject)
{
Validate.IsNotNull(nameof(dbColumns), dbColumns);
Validate.IsNotNull(nameof(smoObject), smoObject);
@@ -46,15 +46,24 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
// identify a row in the table
bool isTrustworthyForUniqueness = dbColumn.IsUpdatable || smoColumn.Identity;
+ // The default value may be escaped
+ string defaultValue = smoColumn.DefaultConstraint == null
+ ? null
+ : SqlScriptFormatter.UnwrapLiteral(smoColumn.DefaultConstraint.Text);
+
EditColumnWrapper column = new EditColumnWrapper
{
DbColumn = dbColumn,
Ordinal = i,
+ DefaultValue = defaultValue,
EscapedName = SqlScriptFormatter.FormatIdentifier(dbColumn.ColumnName),
IsTrustworthyForUniqueness = isTrustworthyForUniqueness,
// A key column is determined by whether it is in the primary key and trustworthy
- IsKey = smoColumn.InPrimaryKey && isTrustworthyForUniqueness
+ IsKey = smoColumn.InPrimaryKey && isTrustworthyForUniqueness,
+
+ // A column is calculated if it is identity, computed, or otherwise not updatable
+ IsCalculated = smoColumn.Identity || smoColumn.Computed || !dbColumn.IsUpdatable
};
columns.Add(column);
}
@@ -80,7 +89,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
///
/// Read-only list of columns in the object being edited
///
- public IEnumerable Columns => columns.AsReadOnly();
+ public IReadOnlyList Columns => columns.AsReadOnly();
///
/// Full escaped multipart identifier for the object being edited
@@ -95,6 +104,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
///
/// Read-only list of columns that are used to uniquely identify a row
///
- public IEnumerable KeyColumns => keyColumns.AsReadOnly();
+ public IReadOnlyList KeyColumns => keyColumns.AsReadOnly();
}
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
index 50bccdc7..513fb1ee 100755
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
@@ -501,6 +501,14 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
+ public static string EditDataComputedColumnPlaceholder
+ {
+ get
+ {
+ return Keys.GetString(Keys.EditDataComputedColumnPlaceholder);
+ }
+ }
+
public static string EditDataInitializeInProgress
{
get
@@ -1054,6 +1062,9 @@ namespace Microsoft.SqlTools.ServiceLayer
public const string EditDataCommitInProgress = "EditDataCommitInProgress";
+ public const string EditDataComputedColumnPlaceholder = "EditDataComputedColumnPlaceholder";
+
+
public const string EditDataInitializeInProgress = "EditDataInitializeInProgress";
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
index c7f5ae88..b0b3787d 100755
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
@@ -423,6 +423,10 @@
A commit task is in progress. Please wait for completion.
+
+ <TBD>
+
+
Another edit data initialize is in progress for this owner URI. Please wait for completion.
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
index 72ad9a72..206c19bd 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
@@ -200,6 +200,8 @@ EditDataScriptFilePathNull = An output filename must be provided
EditDataCommitInProgress = A commit task is in progress. Please wait for completion.
+EditDataComputedColumnPlaceholder =
+
EditDataInitializeInProgress = Another edit data initialize is in progress for this owner URI. Please wait for completion.
############################################################################
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
index fd16ede6..da181095 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
@@ -531,9 +531,9 @@
Decimal column is missing numeric precision or numeric scale
-
- Cannot add row to result buffer, data reader does not contain rows
- Cannot add row to result buffer, data reader does not contain rows
+
+ <TBD>
+ <TBD>
@@ -541,6 +541,11 @@
Another edit data initialize is in progress for this owner URI. Please wait for completion.
+
+ Cannot add row to result buffer, data reader does not contain rows
+ Cannot add row to result buffer, data reader does not contain rows
+
+