NULL column validation when updating cells (#274)

* Adding validation that NULL is allowed when setting cell values

* Adding unit tests
This commit is contained in:
Benjamin Russell
2017-03-09 16:14:25 -08:00
committed by GitHub
parent 8f3e83b519
commit f2afa07a93
6 changed files with 50 additions and 8 deletions

View File

@@ -38,8 +38,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
// Check for null
if (valueAsString == NullString)
{
Value = DBNull.Value;
ValueAsString = valueAsString;
ProcessNullValue();
}
else if (columnType == typeof(byte[]))
{
@@ -197,6 +196,18 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
ValueAsString = Value.ToString();
}
private void ProcessNullValue()
{
// Make sure that nulls are allowed if we set it to null
if (!Column.AllowDBNull.HasTrue())
{
throw new InvalidOperationException(SR.EditDataNullNotAllowed);
}
Value = DBNull.Value;
ValueAsString = NullString;
}
#endregion
}
}

View File

@@ -525,6 +525,14 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
public static string EditDataNullNotAllowed
{
get
{
return Keys.GetString(Keys.EditDataNullNotAllowed);
}
}
public static string EE_BatchSqlMessageNoProcedureInfo
{
get
@@ -1079,6 +1087,9 @@ namespace Microsoft.SqlTools.ServiceLayer
public const string EditDataInitializeInProgress = "EditDataInitializeInProgress";
public const string EditDataNullNotAllowed = "EditDataNullNotAllowed";
public const string EE_BatchSqlMessageNoProcedureInfo = "EE_BatchSqlMessageNoProcedureInfo";

View File

@@ -435,6 +435,10 @@
<value>Another edit data initialize is in progress for this owner URI. Please wait for completion.</value>
<comment></comment>
</data>
<data name="EditDataNullNotAllowed" xml:space="preserve">
<value>NULL is not allowed for this column</value>
<comment></comment>
</data>
<data name="EE_BatchSqlMessageNoProcedureInfo" xml:space="preserve">
<value>Msg {0}, Level {1}, State {2}, Line {3}</value>
<comment></comment>

View File

@@ -206,6 +206,8 @@ EditDataComputedColumnPlaceholder = <TBD>
EditDataInitializeInProgress = Another edit data initialize is in progress for this owner URI. Please wait for completion.
EditDataNullNotAllowed = NULL is not allowed for this column
############################################################################
# DacFx Resources

View File

@@ -551,6 +551,11 @@
<target state="new">Cannot add row to result buffer, data reader does not contain rows</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataNullNotAllowed">
<source>NULL is not allowed for this column</source>
<target state="new">NULL is not allowed for this column</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>