Adding validation of timespan columns w/in 24hrs (#275)

Very small feature add to make sure that values entered for `TIME` columns are < 24hrs. If the value is >=24hrs when setting the column, an exception will be thrown that the edit/updateCell handler will catch and convert into an error on the JSON RPC side.

* Adding validation of timespan columns

* Fixing a merge conflict
This commit is contained in:
Benjamin Russell
2017-03-10 13:46:13 -08:00
committed by GitHub
parent 125fe8b0e7
commit 471e64fb1c
7 changed files with 730 additions and 979 deletions

View File

@@ -19,6 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
private const string NullString = @"NULL";
private const string TextNullString = @"'NULL'";
private static readonly Regex HexRegex = new Regex("0x[0-9A-F]+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly TimeSpan MaxTimespan = TimeSpan.FromHours(24);
/// <summary>
/// Constructs a new cell update based on the the string value provided and the column
@@ -59,8 +60,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
}
else if (columnType == typeof(TimeSpan))
{
Value = TimeSpan.Parse(valueAsString, CultureInfo.CurrentCulture);
ValueAsString = Value.ToString();
ProcessTimespanColumn(valueAsString);
}
else if (columnType == typeof(DateTimeOffset))
{
@@ -196,6 +196,18 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
ValueAsString = Value.ToString();
}
private void ProcessTimespanColumn(string valueAsString)
{
TimeSpan ts = TimeSpan.Parse(valueAsString, CultureInfo.CurrentCulture);
if (ts >= MaxTimespan)
{
throw new InvalidOperationException(SR.EditDataTimeOver24Hrs);
}
Value = ts;
ValueAsString = Value.ToString();
}
private void ProcessNullValue()
{
// Make sure that nulls are allowed if we set it to null