Alan Ren
2018-08-14 14:00:46 -07:00
committed by GitHub
parent fb157520d9
commit df3c312984
2 changed files with 29 additions and 9 deletions

View File

@@ -22,6 +22,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
/// </summary> /// </summary>
public bool IsNull { get; set; } public bool IsNull { get; set; }
/// <summary>
/// Culture invariant display value for the cell, this value can later be used by the client to convert back to the original value.
/// </summary>
public string InvariantCultureDisplayValue { get; set; }
/// <summary> /// <summary>
/// The raw object for the cell, for use internally /// The raw object for the cell, for use internally
/// </summary> /// </summary>
@@ -42,6 +47,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
Validate.IsNotNull(nameof(other), other); Validate.IsNotNull(nameof(other), other);
other.DisplayValue = DisplayValue; other.DisplayValue = DisplayValue;
other.InvariantCultureDisplayValue = InvariantCultureDisplayValue;
other.IsNull = IsNull; other.IsNull = IsNull;
other.RawObject = RawObject; other.RawObject = RawObject;
other.RowId = RowId; other.RowId = RowId;

View File

@@ -151,7 +151,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
// Use the right read function for the type to read the data from the file // Use the right read function for the type to read the data from the file
ReadMethod readFunc; ReadMethod readFunc;
if(!readMethods.TryGetValue(colType, out readFunc)) if (!readMethods.TryGetValue(colType, out readFunc))
{ {
// Treat everything else as a string // Treat everything else as a string
readFunc = readMethods[typeof(string)]; readFunc = readMethods[typeof(string)];
@@ -193,15 +193,17 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
/// If provided, this function will be used to determine if the value is null /// If provided, this function will be used to determine if the value is null
/// </param> /// </param>
/// <param name="toStringFunc">Optional function to use to convert the object to a string.</param> /// <param name="toStringFunc">Optional function to use to convert the object to a string.</param>
/// <param name="setInvariantCultureDisplayValue">Optional parameter indicates whether the culture invariant display value should be provided.</param>
/// <typeparam name="T">The expected type of the cell. Used to keep the code honest</typeparam> /// <typeparam name="T">The expected type of the cell. Used to keep the code honest</typeparam>
/// <returns>The object, a display value, and the length of the value + its length</returns> /// <returns>The object, a display value, and the length of the value + its length</returns>
private FileStreamReadResult ReadCellHelper<T>(long offset, long rowId, private FileStreamReadResult ReadCellHelper<T>(long offset, long rowId,
Func<int, T> convertFunc, Func<int, T> convertFunc,
Func<int, bool> isNullFunc = null, Func<int, bool> isNullFunc = null,
Func<T, string> toStringFunc = null) Func<T, string> toStringFunc = null,
bool setInvariantCultureDisplayValue = false)
{ {
LengthResult length = ReadLength(offset); LengthResult length = ReadLength(offset);
DbCellValue result = new DbCellValue {RowId = rowId}; DbCellValue result = new DbCellValue { RowId = rowId };
if (isNullFunc == null ? length.ValueLength == 0 : isNullFunc(length.TotalLength)) if (isNullFunc == null ? length.ValueLength == 0 : isNullFunc(length.TotalLength))
{ {
@@ -216,6 +218,17 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
T resultObject = convertFunc(length.ValueLength); T resultObject = convertFunc(length.ValueLength);
result.RawObject = resultObject; result.RawObject = resultObject;
result.DisplayValue = toStringFunc == null ? result.RawObject.ToString() : toStringFunc(resultObject); result.DisplayValue = toStringFunc == null ? result.RawObject.ToString() : toStringFunc(resultObject);
if (setInvariantCultureDisplayValue)
{
string icDisplayValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", result.RawObject);
// Only set the value when it is different from the DisplayValue to reduce the size of the result
//
if (icDisplayValue != result.DisplayValue)
{
result.InvariantCultureDisplayValue = icDisplayValue;
}
}
result.IsNull = false; result.IsNull = false;
} }
@@ -300,7 +313,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
/// <returns>A single</returns> /// <returns>A single</returns>
internal FileStreamReadResult ReadSingle(long fileOffset, long rowId) internal FileStreamReadResult ReadSingle(long fileOffset, long rowId)
{ {
return ReadCellHelper(fileOffset, rowId, length => BitConverter.ToSingle(buffer, 0)); return ReadCellHelper(fileOffset, rowId, length => BitConverter.ToSingle(buffer, 0), setInvariantCultureDisplayValue: true);
} }
/// <summary> /// <summary>
@@ -311,7 +324,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
/// <returns>A double</returns> /// <returns>A double</returns>
internal FileStreamReadResult ReadDouble(long fileOffset, long rowId) internal FileStreamReadResult ReadDouble(long fileOffset, long rowId)
{ {
return ReadCellHelper(fileOffset, rowId, length => BitConverter.ToDouble(buffer, 0)); return ReadCellHelper(fileOffset, rowId, length => BitConverter.ToDouble(buffer, 0), setInvariantCultureDisplayValue: true);
} }
/// <summary> /// <summary>
@@ -326,7 +339,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
int[] arrInt32 = new int[(length - 3) / 4]; int[] arrInt32 = new int[(length - 3) / 4];
Buffer.BlockCopy(buffer, 3, arrInt32, 0, length - 3); Buffer.BlockCopy(buffer, 3, arrInt32, 0, length - 3);
return new SqlDecimal(buffer[0], buffer[1], buffer[2] == 1, arrInt32); return new SqlDecimal(buffer[0], buffer[1], buffer[2] == 1, arrInt32);
}); }, setInvariantCultureDisplayValue: true);
} }
/// <summary> /// <summary>
@@ -341,7 +354,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
int[] arrInt32 = new int[length / 4]; int[] arrInt32 = new int[length / 4];
Buffer.BlockCopy(buffer, 0, arrInt32, 0, length); Buffer.BlockCopy(buffer, 0, arrInt32, 0, length);
return new decimal(arrInt32); return new decimal(arrInt32);
}); }, setInvariantCultureDisplayValue: true);
} }
/// <summary> /// <summary>
@@ -402,7 +415,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
{ {
// DateTimeOffset is represented by DateTime.Ticks followed by TimeSpan.Ticks // DateTimeOffset is represented by DateTime.Ticks followed by TimeSpan.Ticks
// both as Int64 values // both as Int64 values
return ReadCellHelper(offset, rowId, length => { return ReadCellHelper(offset, rowId, length =>
{
long dtTicks = BitConverter.ToInt64(buffer, 0); long dtTicks = BitConverter.ToInt64(buffer, 0);
long dtOffset = BitConverter.ToInt64(buffer, 8); long dtOffset = BitConverter.ToInt64(buffer, 8);
return new DateTimeOffset(new DateTime(dtTicks), new TimeSpan(dtOffset)); return new DateTimeOffset(new DateTime(dtTicks), new TimeSpan(dtOffset));