mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 09:35:38 -05:00
Edit Data: Better errors for possible truncation (#514)
* Fix to make sql exceptions surface properly to user (with important notes!) * Adding support for detecting column size issues when updating a cell * Adding unit tests for the exception on read scenario
This commit is contained in:
committed by
Karl Burtram
parent
9499d73cec
commit
e9bc97e290
@@ -49,10 +49,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
}
|
||||
else if (columnType == typeof(string))
|
||||
{
|
||||
// Special case for strings because the string value should stay the same as provided
|
||||
// If user typed 'NULL' they mean NULL as text
|
||||
Value = valueAsString == TextNullString ? NullString : valueAsString;
|
||||
ValueAsString = valueAsString;
|
||||
ProcessTextCell(valueAsString);
|
||||
}
|
||||
else if (columnType == typeof(Guid))
|
||||
{
|
||||
@@ -245,6 +242,23 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
ValueAsString = NullString;
|
||||
}
|
||||
|
||||
private void ProcessTextCell(string valueAsString)
|
||||
{
|
||||
// Special case for strings because the string value should stay the same as provided
|
||||
// If user typed 'NULL' they mean NULL as text
|
||||
Value = valueAsString == TextNullString ? NullString : valueAsString;
|
||||
|
||||
// Make sure that the value fits inside the size of the column
|
||||
if (Column.ColumnSize.HasValue && valueAsString.Length > Column.ColumnSize)
|
||||
{
|
||||
string columnSizeString = $"({Column.ColumnSize.Value})";
|
||||
string columnTypeString = Column.DataTypeName.ToUpperInvariant() + columnSizeString;
|
||||
throw new FormatException(SR.EditDataValueTooLarge(valueAsString, columnTypeString));
|
||||
}
|
||||
|
||||
ValueAsString = valueAsString;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user