From 21470b0929c9d8c31fd4022637e9f57cc9da0d60 Mon Sep 17 00:00:00 2001 From: Jordan Hays Date: Thu, 15 Sep 2022 13:28:04 -0700 Subject: [PATCH 1/3] remove dropped ledger columns from Edit Data columns --- .../EditData/SmoEditMetadataFactory.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs index 510d1fc64b..207a3232d9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs @@ -99,6 +99,12 @@ public EditTableMetadata GetObjectMetadata(DbConnection connection, string[] obj { Column smoColumn = smoResult.Columns[i]; + // Don't return columns that are dropped + if (smoColumn.IsDroppedLedgerColumn) + { + continue; + } + string defaultValue = null; try { From b6e57076dd00ccec9a8ec3d03a5d82942f237bf5 Mon Sep 17 00:00:00 2001 From: Jordan Hays Date: Mon, 19 Sep 2022 13:09:22 -0700 Subject: [PATCH 2/3] moving dropped ledger filtering to column retrieval from SMO --- .../EditData/SmoEditMetadataFactory.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs index 207a3232d9..d915e5e71f 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs @@ -86,6 +86,10 @@ public EditTableMetadata GetObjectMetadata(DbConnection connection, string[] obj throw new ArgumentOutOfRangeException(nameof(objectType), SR.EditDataUnsupportedObjectType(objectType)); } + // Filter out dropped ledger columns from the list of columns to be returned + // + smoResult.Columns.ClearAndInitialize("[(@IsDroppedLedgerColumn=0)]", new [] {nameof(Column.IsDroppedLedgerColumn), nameof(Column.DataType)}); + // A bug in SMO makes it necessary to call refresh to attain certain properties (such as IsMemoryOptimized) smoResult.Refresh(); if (smoResult.State != SqlSmoState.Existing) @@ -99,12 +103,6 @@ public EditTableMetadata GetObjectMetadata(DbConnection connection, string[] obj { Column smoColumn = smoResult.Columns[i]; - // Don't return columns that are dropped - if (smoColumn.IsDroppedLedgerColumn) - { - continue; - } - string defaultValue = null; try { From b352be0118339e62a64fdc3b046a0cc60c680a32 Mon Sep 17 00:00:00 2001 From: Jordan Hays Date: Mon, 19 Sep 2022 14:35:25 -0700 Subject: [PATCH 3/3] fix clear and initialize placement and retrieve DefaultConstraintName --- .../EditData/SmoEditMetadataFactory.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs index d915e5e71f..4cfc49caeb 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/SmoEditMetadataFactory.cs @@ -86,10 +86,6 @@ public EditTableMetadata GetObjectMetadata(DbConnection connection, string[] obj throw new ArgumentOutOfRangeException(nameof(objectType), SR.EditDataUnsupportedObjectType(objectType)); } - // Filter out dropped ledger columns from the list of columns to be returned - // - smoResult.Columns.ClearAndInitialize("[(@IsDroppedLedgerColumn=0)]", new [] {nameof(Column.IsDroppedLedgerColumn), nameof(Column.DataType)}); - // A bug in SMO makes it necessary to call refresh to attain certain properties (such as IsMemoryOptimized) smoResult.Refresh(); if (smoResult.State != SqlSmoState.Existing) @@ -97,6 +93,10 @@ public EditTableMetadata GetObjectMetadata(DbConnection connection, string[] obj throw new ArgumentOutOfRangeException(nameof(objectNamedParts), SR.EditDataObjectNotFound); } + // Filter out dropped ledger columns from the list of columns to be returned + // and grab the specific column properties checked below + smoResult.Columns.ClearAndInitialize("[(@IsDroppedLedgerColumn=0)]", new [] { nameof(Column.DataType), nameof(Column.DefaultConstraintName) }); + // Generate the edit column metadata List editColumns = new List(); for (int i = 0; i < smoResult.Columns.Count; i++) @@ -107,7 +107,7 @@ public EditTableMetadata GetObjectMetadata(DbConnection connection, string[] obj try { // The default value may be escaped - defaultValue = smoColumn.DefaultConstraint == null + defaultValue = string.IsNullOrEmpty(smoColumn.DefaultConstraintName) ? null : FromSqlScript.UnwrapLiteral(smoColumn.DefaultConstraint.Text); }