mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-21 17:24:03 -05:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user