diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index cefabcb537..aad5b77969 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -1253,7 +1253,7 @@ protected override void OnRowUpdating(System.Data.Common.RowUpdatingEventArgs va object System.ICloneable.Clone() { throw null; } } /// - public partial class SqlDataReader : System.Data.Common.DbDataReader, System.Data.IDataReader, System.IDisposable + public partial class SqlDataReader : System.Data.Common.DbDataReader, System.Data.IDataReader, System.Data.Common.IDbColumnSchemaGenerator, System.IDisposable { internal SqlDataReader() { } /// @@ -1290,7 +1290,8 @@ public override void Close() { } /// public override long GetChars(int i, long dataIndex, char[] buffer, int bufferIndex, int length) { throw null; } /// - public System.Collections.ObjectModel.ReadOnlyCollection GetColumnSchema() { throw null; }/// + public System.Collections.ObjectModel.ReadOnlyCollection GetColumnSchema() { throw null; } + /// public override string GetDataTypeName(int i) { throw null; } /// public override System.DateTime GetDateTime(int i) { throw null; } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 6246fc590d..ef1e3eaad7 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -437,6 +437,9 @@ Microsoft\Data\SqlClient\SqlDataAdapter.cs + + Microsoft\Data\SqlClient\SqlDbColumn.cs + Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs @@ -654,7 +657,6 @@ - diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs index 9ad6c68967..848f10283a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs @@ -1255,7 +1255,7 @@ protected override void OnRowUpdating(System.Data.Common.RowUpdatingEventArgs va protected override void TerminateBatching() { } } /// - public partial class SqlDataReader : System.Data.Common.DbDataReader, System.Data.IDataReader, System.IDisposable + public partial class SqlDataReader : System.Data.Common.DbDataReader, System.Data.IDataReader, System.Data.Common.IDbColumnSchemaGenerator, System.IDisposable { internal SqlDataReader() { } /// @@ -1291,6 +1291,8 @@ public override void Close() { } public override char GetChar(int i) { throw null; } /// public override long GetChars(int i, long dataIndex, char[] buffer, int bufferIndex, int length) { throw null; } + /// + public System.Collections.ObjectModel.ReadOnlyCollection GetColumnSchema() { throw null; } /// public override string GetDataTypeName(int i) { throw null; } /// diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj index b326e42977..783ebbef83 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj @@ -44,6 +44,7 @@ + diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 591977ef2d..afbe5f2dc3 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -649,6 +649,9 @@ Microsoft\Data\SqlClient\SqlDataAdapter.cs + + Microsoft\Data\SqlClient\SqlDbColumn.cs + Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs index 2cd5370c8e..fb94a7e161 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs @@ -4,6 +4,7 @@ using System; using System.Collections; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Data.Common; @@ -27,7 +28,7 @@ namespace Microsoft.Data.SqlClient { /// - public class SqlDataReader : DbDataReader, IDataReader + public class SqlDataReader : DbDataReader, IDataReader, IDbColumnSchemaGenerator { private enum ALTROWSTATUS { @@ -74,6 +75,7 @@ internal class SharedState private CommandBehavior _commandBehavior; private static int s_objectTypeCount; // EventSource Counter + private static readonly ReadOnlyCollection s_emptySchema = new ReadOnlyCollection(Array.Empty()); internal readonly int ObjectID = Interlocked.Increment(ref s_objectTypeCount); @@ -6360,5 +6362,73 @@ private void SwitchToAsyncWithoutSnapshot() _stateObj._asyncReadWithoutSnapshot = true; } - }// SqlDataReader -}// namespace + /// + public ReadOnlyCollection GetColumnSchema() + { + SqlStatistics statistics = null; + try + { + statistics = SqlStatistics.StartTimer(Statistics); + if (_metaData == null || _metaData.dbColumnSchema == null) + { + if (this.MetaData != null) + { + + _metaData.dbColumnSchema = BuildColumnSchema(); + Debug.Assert(_metaData.dbColumnSchema != null, "No schema information yet!"); + // filter table? + } + } + if (_metaData != null) + { + return _metaData.dbColumnSchema; + } + return s_emptySchema; + } + finally + { + SqlStatistics.StopTimer(statistics); + } + } + + private ReadOnlyCollection BuildColumnSchema() + { + _SqlMetaDataSet md = MetaData; + DbColumn[] columnSchema = new DbColumn[md.Length]; + for (int i = 0; i < md.Length; i++) + { + _SqlMetaData col = md[i]; + SqlDbColumn dbColumn = new SqlDbColumn(md[i]); + + if (_typeSystem <= SqlConnectionString.TypeSystem.SQLServer2005 && col.Is2008DateTimeType) + { + dbColumn.SqlNumericScale = MetaType.MetaNVarChar.Scale; + } + else if (TdsEnums.UNKNOWN_PRECISION_SCALE != col.scale) + { + dbColumn.SqlNumericScale = col.scale; + } + else + { + dbColumn.SqlNumericScale = col.metaType.Scale; + } + + if (_browseModeInfoConsumed) + { + dbColumn.SqlIsAliased = col.IsDifferentName; + dbColumn.SqlIsKey = col.IsKey; + dbColumn.SqlIsHidden = col.IsHidden; + dbColumn.SqlIsExpression = col.IsExpression; + } + + dbColumn.SqlDataType = GetFieldTypeInternal(col); + + dbColumn.SqlDataTypeName = GetDataTypeNameInternal(col); + + columnSchema[i] = dbColumn; + } + + return new ReadOnlyCollection(columnSchema); + } + } +} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj index c092b35a98..a07e66579c 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj @@ -12,8 +12,8 @@ + - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDbColumn.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDbColumn.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDbColumn.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDbColumn.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs index 892aaa0a89..1d4d89090a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs @@ -305,9 +305,7 @@ internal sealed partial class _SqlMetaDataSet internal DataTable schemaTable; private readonly _SqlMetaData[] _metaDataArray; -#if !NETFRAMEWORK internal ReadOnlyCollection dbColumnSchema; -#endif private int _hiddenColumnCount; private int[] _visibleColumnMap; @@ -327,11 +325,9 @@ private _SqlMetaDataSet(_SqlMetaDataSet original) id = original.id; _hiddenColumnCount = original._hiddenColumnCount; _visibleColumnMap = original._visibleColumnMap; -#if !NETFRAMEWORK dbColumnSchema = original.dbColumnSchema; -#else schemaTable = original.schemaTable; -#endif + if (original._metaDataArray == null) { _metaDataArray = null; diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs index bdbd805e73..0fd8f22daf 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; -using System.Data.Common; using System.Data.SqlTypes; using System.Globalization; using System.IO; @@ -252,7 +251,6 @@ private static void TestUdtSqlDataReaderGetStream(CommandBehavior behavior) } // Synapse: Parse error at line: 1, column: 41: Incorrect syntax near 'hierarchyid'. - [ActiveIssue("25421", TargetFrameworkMonikers.NetFramework)] [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] public static void TestUdtSchemaMetadata() { @@ -263,9 +261,9 @@ public static void TestUdtSchemaMetadata() command.CommandText = "select hierarchyid::Parse('/1/1/3/') as col0, geometry::Parse('LINESTRING (100 100, 20 180, 180 180)') as col1, geography::Parse('LINESTRING(-122.360 47.656, -122.343 47.656)') as col2"; using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SchemaOnly)) { - ReadOnlyCollection columns = reader.GetColumnSchema(); + ReadOnlyCollection columns = reader.GetColumnSchema(); - DbColumn column = null; + System.Data.Common.DbColumn column = null; // Validate Microsoft.SqlServer.Types.SqlHierarchyId, Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 column = columns[0]; diff --git a/tools/props/Versions.props b/tools/props/Versions.props index 6bbbe81371..8f2107f086 100644 --- a/tools/props/Versions.props +++ b/tools/props/Versions.props @@ -28,6 +28,7 @@ 4.5.5 6.0.0 6.0.10 + 4.3.0 diff --git a/tools/specs/Microsoft.Data.SqlClient.nuspec b/tools/specs/Microsoft.Data.SqlClient.nuspec index 8f583fb959..35fbb5c7ae 100644 --- a/tools/specs/Microsoft.Data.SqlClient.nuspec +++ b/tools/specs/Microsoft.Data.SqlClient.nuspec @@ -37,6 +37,7 @@ When using NuGet 3.x this package requires at least version 3.4. +