From cb290cdbb5c2f9a6f761e5912e6bc6c4d0ede743 Mon Sep 17 00:00:00 2001 From: Karl Burtram Date: Wed, 15 Dec 2021 11:15:11 -0800 Subject: [PATCH] Revert query execution changes (#1341) * Revert "handle sql variable type (#1333)" This reverts commit 51c801eb33aa9589140d1b4eb5fcab63345f81d8. * Revert "handle large decimal (#1326)" This reverts commit fd5b8af0c05799052f64311808179babca142994. --- .../Localization/sr.cs | 8 ------ .../Localization/sr.resx | 5 ---- .../Localization/sr.strings | 2 -- .../Localization/sr.xlf | 14 +++++++--- .../ServiceBufferFileStreamReader.cs | 15 +++++------ .../ServiceBufferFileStreamWriter.cs | 26 +++++++++---------- .../DataStorage/StorageDataReader.cs | 4 +-- .../DataStorage/StorageDataReaderTests.cs | 20 +++----------- 8 files changed, 35 insertions(+), 59 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index 684f4cea..5cb28ee4 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -8631,11 +8631,6 @@ namespace Microsoft.SqlTools.ServiceLayer return Keys.GetString(Keys.QueryServiceQueryFailed, message); } - public static string QueryServiceUnsupportedSqlVariantType(string underlyingType, string columnName) - { - return Keys.GetString(Keys.QueryServiceUnsupportedSqlVariantType, underlyingType, columnName); - } - public static string QueryServiceSaveAsFail(string fileName, string message) { return Keys.GetString(Keys.QueryServiceSaveAsFail, fileName, message); @@ -9016,9 +9011,6 @@ namespace Microsoft.SqlTools.ServiceLayer public const string QueryServiceResultSetTooLarge = "QueryServiceResultSetTooLarge"; - public const string QueryServiceUnsupportedSqlVariantType = "QueryServiceUnsupportedSqlVariantType"; - - public const string QueryServiceSaveAsResultSetNotComplete = "QueryServiceSaveAsResultSetNotComplete"; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index 74435378..a2e5b6db 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -303,11 +303,6 @@ Result set has too many rows to be safely loaded - - The underlying type "{0}" for sql variant column "{1}" could not be resolved. - . - Parameters: 0 - underlyingType (string), 1 - columnName (string) - Result cannot be saved until query execution has completed diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index 60d6183d..72c0a886 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -124,8 +124,6 @@ QueryServiceResultSetHasNoResults = Query has no results to return QueryServiceResultSetTooLarge = Result set has too many rows to be safely loaded -QueryServiceUnsupportedSqlVariantType(string underlyingType, string columnName) = The underlying type "{0}" for sql variant column "{1}" could not be resolved. - ### Save As Requests QueryServiceSaveAsResultSetNotComplete = Result cannot be saved until query execution has completed diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index e20d0667..794925cb 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -5696,11 +5696,17 @@ Specifies whether the check constraint is Enabled - - The underlying type "{0}" for sql variant column "{1}" could not be resolved. - The underlying type "{0}" for sql variant column "{1}" could not be resolved. + + Unable to start streaming session {0} due to missing session details. + Unable to start streaming session {0} due to missing session details. . - Parameters: 0 - underlyingType (string), 1 - columnName (string) + Parameters: 0 - id (int) + + + Failed to start profiler: {0} + Failed to start profiler: {0} + . + Parameters: 0 - error (String) diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/ServiceBufferFileStreamReader.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/ServiceBufferFileStreamReader.cs index 2fea95e0..de22f564 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/ServiceBufferFileStreamReader.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/ServiceBufferFileStreamReader.cs @@ -76,7 +76,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage {typeof(bool), (o, id, col) => ReadBoolean(o, id)}, {typeof(double), (o, id, col) => ReadDouble(o, id)}, {typeof(float), (o, id, col) => ReadSingle(o, id)}, - {typeof(decimal), (o, id, col) => ReadSqlDecimal(o, id)}, + {typeof(decimal), (o, id, col) => ReadDecimal(o, id)}, {typeof(DateTime), ReadDateTime}, {typeof(DateTimeOffset), (o, id, col) => ReadDateTimeOffset(o, id)}, {typeof(TimeSpan), (o, id, col) => ReadTimeSpan(o, id)}, @@ -134,15 +134,14 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage continue; } - // We need to specify the assembly name for SQL types in order to resolve the type correctly. - if (sqlVariantType.StartsWith("System.Data.SqlTypes.")) - { - sqlVariantType = sqlVariantType + ", System.Data.Common"; - } + // The typename is stored in the string colType = Type.GetType(sqlVariantType); - if (colType == null) + + // Workaround .NET bug, see sqlbu# 440643 and vswhidbey# 599834 + // TODO: Is this workaround necessary for .NET Core? + if (colType == null && sqlVariantType == "System.Data.SqlTypes.SqlSingle") { - throw new ArgumentException(SR.QueryServiceUnsupportedSqlVariantType(sqlVariantType, column.ColumnName)); + colType = typeof(SqlSingle); } } else diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/ServiceBufferFileStreamWriter.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/ServiceBufferFileStreamWriter.cs index 3267b6c9..522bdd55 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/ServiceBufferFileStreamWriter.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/ServiceBufferFileStreamWriter.cs @@ -92,19 +92,19 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage {typeof(byte[]), val => WriteBytes((byte[]) val)}, {typeof(Guid), val => WriteGuid((Guid) val)}, - {typeof(SqlString), val => WriteNullable((SqlString) val, obj => WriteString(((SqlString) obj).Value))}, - {typeof(SqlInt16), val => WriteNullable((SqlInt16) val, obj => WriteInt16(((SqlInt16) obj).Value))}, - {typeof(SqlInt32), val => WriteNullable((SqlInt32) val, obj => WriteInt32(((SqlInt32)obj).Value))}, - {typeof(SqlInt64), val => WriteNullable((SqlInt64) val, obj => WriteInt64(((SqlInt64) obj).Value)) }, - {typeof(SqlByte), val => WriteNullable((SqlByte) val, obj => WriteByte(((SqlByte) obj).Value)) }, - {typeof(SqlBoolean), val => WriteNullable((SqlBoolean) val, obj => WriteBoolean(((SqlBoolean) obj).Value)) }, - {typeof(SqlDouble), val => WriteNullable((SqlDouble) val, obj => WriteDouble(((SqlDouble) obj).Value)) }, - {typeof(SqlSingle), val => WriteNullable((SqlSingle) val, obj => WriteSingle(((SqlSingle) obj).Value)) }, + {typeof(SqlString), val => WriteNullable((SqlString) val, obj => WriteString((string) obj))}, + {typeof(SqlInt16), val => WriteNullable((SqlInt16) val, obj => WriteInt16((short) obj))}, + {typeof(SqlInt32), val => WriteNullable((SqlInt32) val, obj => WriteInt32((int) obj))}, + {typeof(SqlInt64), val => WriteNullable((SqlInt64) val, obj => WriteInt64((long) obj)) }, + {typeof(SqlByte), val => WriteNullable((SqlByte) val, obj => WriteByte((byte) obj)) }, + {typeof(SqlBoolean), val => WriteNullable((SqlBoolean) val, obj => WriteBoolean((bool) obj)) }, + {typeof(SqlDouble), val => WriteNullable((SqlDouble) val, obj => WriteDouble((double) obj)) }, + {typeof(SqlSingle), val => WriteNullable((SqlSingle) val, obj => WriteSingle((float) obj)) }, {typeof(SqlDecimal), val => WriteNullable((SqlDecimal) val, obj => WriteSqlDecimal((SqlDecimal) obj)) }, - {typeof(SqlDateTime), val => WriteNullable((SqlDateTime) val, obj => WriteDateTime(((SqlDateTime) obj).Value)) }, - {typeof(SqlBytes), val => WriteNullable((SqlBytes) val, obj => WriteBytes(((SqlBytes) obj).Value)) }, - {typeof(SqlBinary), val => WriteNullable((SqlBinary) val, obj => WriteBytes(((SqlBinary) obj).Value)) }, - {typeof(SqlGuid), val => WriteNullable((SqlGuid) val, obj => WriteGuid(((SqlGuid) obj).Value)) }, + {typeof(SqlDateTime), val => WriteNullable((SqlDateTime) val, obj => WriteDateTime((DateTime) obj)) }, + {typeof(SqlBytes), val => WriteNullable((SqlBytes) val, obj => WriteBytes((byte[]) obj)) }, + {typeof(SqlBinary), val => WriteNullable((SqlBinary) val, obj => WriteBytes((byte[]) obj)) }, + {typeof(SqlGuid), val => WriteNullable((SqlGuid) val, obj => WriteGuid((Guid) obj)) }, {typeof(SqlMoney), val => WriteNullable((SqlMoney) val, obj => WriteMoney((SqlMoney) obj)) } }; } @@ -299,7 +299,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage internal int WriteBoolean(bool val) { byteBuffer[0] = 0x01; // length - byteBuffer[1] = (byte)(val ? 0x01 : 0x00); + byteBuffer[1] = (byte) (val ? 0x01 : 0x00); return FileUtilities.WriteWithLength(fileStream, byteBuffer, 2); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/StorageDataReader.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/StorageDataReader.cs index 560e3209..68742616 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/StorageDataReader.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/StorageDataReader.cs @@ -98,7 +98,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage /// The value of the given column public object GetValue(int i) { - return sqlDataReader == null ? DbDataReader.GetValue(i) : sqlDataReader.GetSqlValue(i); + return sqlDataReader == null ? DbDataReader.GetValue(i) : sqlDataReader.GetValue(i); } /// @@ -113,7 +113,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage } else { - sqlDataReader.GetSqlValues(values); + sqlDataReader.GetValues(values); } } diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/QueryExecution/DataStorage/StorageDataReaderTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/QueryExecution/DataStorage/StorageDataReaderTests.cs index e65fa5e7..f5b35462 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/QueryExecution/DataStorage/StorageDataReaderTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/QueryExecution/DataStorage/StorageDataReaderTests.cs @@ -44,20 +44,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt Assert.NotNull(bytes); } - /// - /// Validate GetBytesWithMaxCapacity - /// - [Test] - public void GetLongDecimalTest() - { - // SQL Server support up to 38 digits of decimal - var storageReader = GetTestStorageDataReader( - "SELECT 99999999999999999999999999999999999999"); - storageReader.DbDataReader.Read(); - var value = storageReader.GetValue(0); - Assert.AreEqual("99999999999999999999999999999999999999", value.ToString()); - } - /// /// Validate GetCharsWithMaxCapacity /// @@ -77,7 +63,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt Assert.True(shortName.Length == 2); Assert.Throws(() => storageReader.GetBytesWithMaxCapacity(0, 0)); - Assert.Throws(() => storageReader.GetCharsWithMaxCapacity(0, 0)); + Assert.Throws(() => storageReader.GetCharsWithMaxCapacity(0, 0)); } /// @@ -108,10 +94,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt writer.Write(output); Assert.True(writer.ToString().Equals(output)); writer.Write('.'); - Assert.True(writer.ToString().Equals(output + '.')); + Assert.True(writer.ToString().Equals(output + '.')); writer.Write(output); writer.Write('.'); Assert.True(writer.ToString().Equals(output + '.')); - } + } } } \ No newline at end of file