Edit Data: Fix to work with tables with triggers (#576)

* Moving logic for adding default values to new rows

* Fixing implementation of script generation to handle default values all around

* Unit tests!

* WIP

* Reworking row create script/command generation to work more cleanly and work on triggered tables

* Addressing some bugs with the create row implementation

* Implementing the trigger table fix for row updates
Some small improvements to the create/update tests.
This commit is contained in:
Benjamin Russell
2018-01-10 14:02:07 -08:00
committed by GitHub
parent 4d4e0b1194
commit b7cffa3194
7 changed files with 483 additions and 337 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text.RegularExpressions;
@@ -312,60 +312,61 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.UtilityTests
{
get
{
yield return new object[] {new FormatterTestDbColumn("biGint"), "BIGINT"};
yield return new object[] {new FormatterTestDbColumn("biT"), "BIT"};
yield return new object[] {new FormatterTestDbColumn("deCimal", precision: 18, scale: 0), "DECIMAL(18, 0)"};
yield return new object[] {new FormatterTestDbColumn("deCimal", precision: 22, scale: 2), "DECIMAL(22, 2)"};
yield return new object[] {new FormatterTestDbColumn("inT"), "INT"};
yield return new object[] {new FormatterTestDbColumn("moNey"), "MONEY"};
yield return new object[] {new FormatterTestDbColumn("nuMeric", precision: 18, scale: 0), "NUMERIC(18, 0)"};
yield return new object[] {new FormatterTestDbColumn("nuMeric", precision: 22, scale: 2), "NUMERIC(22, 2)"};
yield return new object[] {new FormatterTestDbColumn("smAllint"), "SMALLINT"};
yield return new object[] {new FormatterTestDbColumn("smAllmoney"), "SMALLMONEY"};
yield return new object[] {new FormatterTestDbColumn("tiNyint"), "TINYINT"};
yield return new object[] {new FormatterTestDbColumn("biNary", size: 255), "BINARY(255)"};
yield return new object[] {new FormatterTestDbColumn("biNary", size: 10), "BINARY(10)"};
yield return new object[] {new FormatterTestDbColumn("vaRbinary", size: 255), "VARBINARY(255)"};
yield return new object[] {new FormatterTestDbColumn("vaRbinary", size: 10), "VARBINARY(10)"};
yield return new object[] {new FormatterTestDbColumn("vaRbinary", size: int.MaxValue), "VARBINARY(MAX)"};
yield return new object[] {new FormatterTestDbColumn("imAge"), "IMAGE"};
yield return new object[] {new FormatterTestDbColumn("smAlldatetime"), "SMALLDATETIME"};
yield return new object[] {new FormatterTestDbColumn("daTetime"), "DATETIME"};
yield return new object[] {new FormatterTestDbColumn("daTetime2", scale: 7), "DATETIME2(7)"};
yield return new object[] {new FormatterTestDbColumn("daTetime2", scale: 0), "DATETIME2(0)"};
yield return new object[] {new FormatterTestDbColumn("daTetimeoffset", scale: 7), "DATETIMEOFFSET(7)"};
yield return new object[] {new FormatterTestDbColumn("daTetimeoffset", scale: 0), "DATETIMEOFFSET(0)"};
yield return new object[] {new FormatterTestDbColumn("tiMe", scale: 7), "TIME(7)"};
yield return new object[] {new FormatterTestDbColumn("flOat"), "FLOAT"};
yield return new object[] {new FormatterTestDbColumn("reAl"), "REAL"};
yield return new object[] {new FormatterTestDbColumn("chAr", size: 1), "CHAR(1)"};
yield return new object[] {new FormatterTestDbColumn("chAr", size: 255), "CHAR(255)"};
yield return new object[] {new FormatterTestDbColumn("ncHar", size: 1), "NCHAR(1)"};
yield return new object[] {new FormatterTestDbColumn("ncHar", size: 255), "NCHAR(255)"};
yield return new object[] {new FormatterTestDbColumn("vaRchar", size: 1), "VARCHAR(1)"};
yield return new object[] {new FormatterTestDbColumn("vaRchar", size: 255), "VARCHAR(255)"};
yield return new object[] {new FormatterTestDbColumn("vaRchar", size: int.MaxValue), "VARCHAR(MAX)"};
yield return new object[] {new FormatterTestDbColumn("nvArchar", size: 1), "NVARCHAR(1)"};
yield return new object[] {new FormatterTestDbColumn("nvArchar", size: 255), "NVARCHAR(255)"};
yield return new object[] {new FormatterTestDbColumn("nvArchar", size: int.MaxValue), "NVARCHAR(MAX)"};
yield return new object[] {new FormatterTestDbColumn("teXt"), "TEXT"};
yield return new object[] {new FormatterTestDbColumn("nteXt"), "NTEXT"};
yield return new object[] {new FormatterTestDbColumn("unIqueidentifier"), "UNIQUEIDENTIFIER"};
yield return new object[] {new FormatterTestDbColumn("sqL_variant"), "SQL_VARIANT"};
yield return new object[] {new FormatterTestDbColumn("somEthing.sys.hierarchyid"), "SOMETHING.SYS.HIERARCHYID"};
yield return new object[] {new FormatterTestDbColumn("geOgraphy"), "GEOGRAPHY"};
yield return new object[] {new FormatterTestDbColumn("geOmetry"), "GEOMETRY"};
yield return new object[] {new FormatterTestDbColumn("sySname"), "SYSNAME"};
yield return new object[] {new FormatterTestDbColumn("tiMestamp"), "TIMESTAMP"};
yield return new object[] {false, new FormatterTestDbColumn("biGint"), "BIGINT"};
yield return new object[] {false, new FormatterTestDbColumn("biT"), "BIT"};
yield return new object[] {false, new FormatterTestDbColumn("deCimal", precision: 18, scale: 0), "DECIMAL(18, 0)"};
yield return new object[] {false, new FormatterTestDbColumn("deCimal", precision: 22, scale: 2), "DECIMAL(22, 2)"};
yield return new object[] {false, new FormatterTestDbColumn("inT"), "INT"};
yield return new object[] {false, new FormatterTestDbColumn("moNey"), "MONEY"};
yield return new object[] {false, new FormatterTestDbColumn("nuMeric", precision: 18, scale: 0), "NUMERIC(18, 0)"};
yield return new object[] {false, new FormatterTestDbColumn("nuMeric", precision: 22, scale: 2), "NUMERIC(22, 2)"};
yield return new object[] {false, new FormatterTestDbColumn("smAllint"), "SMALLINT"};
yield return new object[] {false, new FormatterTestDbColumn("smAllmoney"), "SMALLMONEY"};
yield return new object[] {false, new FormatterTestDbColumn("tiNyint"), "TINYINT"};
yield return new object[] {false, new FormatterTestDbColumn("biNary", size: 255), "BINARY(255)"};
yield return new object[] {false, new FormatterTestDbColumn("biNary", size: 10), "BINARY(10)"};
yield return new object[] {false, new FormatterTestDbColumn("vaRbinary", size: 255), "VARBINARY(255)"};
yield return new object[] {false, new FormatterTestDbColumn("vaRbinary", size: 10), "VARBINARY(10)"};
yield return new object[] {false, new FormatterTestDbColumn("vaRbinary", size: int.MaxValue), "VARBINARY(MAX)"};
yield return new object[] {false, new FormatterTestDbColumn("imAge"), "IMAGE"};
yield return new object[] {false, new FormatterTestDbColumn("smAlldatetime"), "SMALLDATETIME"};
yield return new object[] {false, new FormatterTestDbColumn("daTetime"), "DATETIME"};
yield return new object[] {false, new FormatterTestDbColumn("daTetime2", scale: 7), "DATETIME2(7)"};
yield return new object[] {false, new FormatterTestDbColumn("daTetime2", scale: 0), "DATETIME2(0)"};
yield return new object[] {false, new FormatterTestDbColumn("daTetimeoffset", scale: 7), "DATETIMEOFFSET(7)"};
yield return new object[] {false, new FormatterTestDbColumn("daTetimeoffset", scale: 0), "DATETIMEOFFSET(0)"};
yield return new object[] {false, new FormatterTestDbColumn("tiMe", scale: 7), "TIME(7)"};
yield return new object[] {false, new FormatterTestDbColumn("flOat"), "FLOAT"};
yield return new object[] {false, new FormatterTestDbColumn("reAl"), "REAL"};
yield return new object[] {false, new FormatterTestDbColumn("chAr", size: 1), "CHAR(1)"};
yield return new object[] {false, new FormatterTestDbColumn("chAr", size: 255), "CHAR(255)"};
yield return new object[] {false, new FormatterTestDbColumn("ncHar", size: 1), "NCHAR(1)"};
yield return new object[] {false, new FormatterTestDbColumn("ncHar", size: 255), "NCHAR(255)"};
yield return new object[] {false, new FormatterTestDbColumn("vaRchar", size: 1), "VARCHAR(1)"};
yield return new object[] {false, new FormatterTestDbColumn("vaRchar", size: 255), "VARCHAR(255)"};
yield return new object[] {false, new FormatterTestDbColumn("vaRchar", size: int.MaxValue), "VARCHAR(MAX)"};
yield return new object[] {false, new FormatterTestDbColumn("nvArchar", size: 1), "NVARCHAR(1)"};
yield return new object[] {false, new FormatterTestDbColumn("nvArchar", size: 255), "NVARCHAR(255)"};
yield return new object[] {false, new FormatterTestDbColumn("nvArchar", size: int.MaxValue), "NVARCHAR(MAX)"};
yield return new object[] {false, new FormatterTestDbColumn("teXt"), "TEXT"};
yield return new object[] {false, new FormatterTestDbColumn("nteXt"), "NTEXT"};
yield return new object[] {false, new FormatterTestDbColumn("unIqueidentifier"), "UNIQUEIDENTIFIER"};
yield return new object[] {false, new FormatterTestDbColumn("sqL_variant"), "SQL_VARIANT"};
yield return new object[] {false, new FormatterTestDbColumn("somEthing.sys.hierarchyid"), "HIERARCHYID"};
yield return new object[] {false, new FormatterTestDbColumn("table.geOgraphy"), "GEOGRAPHY"};
yield return new object[] {false, new FormatterTestDbColumn("table.geOmetry"), "GEOMETRY"};
yield return new object[] {false, new FormatterTestDbColumn("sySname"), "SYSNAME"};
yield return new object[] {false, new FormatterTestDbColumn("tiMestamp"), "TIMESTAMP"};
yield return new object[] {true, new FormatterTestDbColumn("tiMestamp"), "VARBINARY(8)"};
}
}
[Theory]
[MemberData(nameof(FormatColumnTypeData))]
public void FormatColumnType(DbColumn input, string expectedOutput)
public void FormatColumnType(bool useSemanticEquivalent, DbColumn input, string expectedOutput)
{
// If: I supply the input columns
string output = ToSqlScript.FormatColumnType(input);
string output = ToSqlScript.FormatColumnType(input, useSemanticEquivalent);
// Then: The output should match the expected output
Assert.Equal(expectedOutput, output);