mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 01:25:40 -05:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user