Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge | Add IDBColumnSchemaGenerator interface to netfx SqlDataReader #2967

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ protected override void OnRowUpdating(System.Data.Common.RowUpdatingEventArgs va
object System.ICloneable.Clone() { throw null; }
}
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/SqlDataReader/*'/>
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() { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/Connection/*'/>
Expand Down Expand Up @@ -1290,7 +1290,8 @@ public override void Close() { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetChars/*'/>
public override long GetChars(int i, long dataIndex, char[] buffer, int bufferIndex, int length) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetColumnSchema/*'/>
public System.Collections.ObjectModel.ReadOnlyCollection<System.Data.Common.DbColumn> GetColumnSchema() { throw null; }/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetDataTypeName/*'/>
public System.Collections.ObjectModel.ReadOnlyCollection<System.Data.Common.DbColumn> GetColumnSchema() { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetDataTypeName/*'/>
public override string GetDataTypeName(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetDateTime/*'/>
public override System.DateTime GetDateTime(int i) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDataAdapter.cs">
<Link>Microsoft\Data\SqlClient\SqlDataAdapter.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDbColumn.cs">
<Link>Microsoft\Data\SqlClient\SqlDbColumn.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs">
<Link>Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs</Link>
</Compile>
Expand Down Expand Up @@ -654,7 +657,6 @@
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionFactory.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionHelper.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlDataReader.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlDbColumn.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlDiagnosticListener.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlTransaction.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ protected override void OnRowUpdating(System.Data.Common.RowUpdatingEventArgs va
protected override void TerminateBatching() { }
}
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/SqlDataReader/*'/>
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() { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/Connection/*'/>
Expand Down Expand Up @@ -1291,6 +1291,8 @@ public override void Close() { }
public override char GetChar(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetChars/*'/>
public override long GetChars(int i, long dataIndex, char[] buffer, int bufferIndex, int length) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetColumnSchema/*'/>
public System.Collections.ObjectModel.ReadOnlyCollection<System.Data.Common.DbColumn> GetColumnSchema() { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetDataTypeName/*'/>
public override string GetDataTypeName(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetDateTime/*'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="$(MicrosoftIdentityModelJsonWebTokensVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
<PackageReference Include="System.Data.Common" Version="$(SystemDataCommonVersion)" />
MichelZ marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="$(SystemSecurityCryptographyPkcsVersion)" />
<PackageReference Include="Microsoft.Bcl.Cryptography" Version="$(MicrosoftBclCryptographyVersion)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDataAdapter.cs">
<Link>Microsoft\Data\SqlClient\SqlDataAdapter.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDbColumn.cs">
<Link>Microsoft\Data\SqlClient\SqlDbColumn.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs">
<Link>Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
Expand All @@ -27,7 +28,7 @@
namespace Microsoft.Data.SqlClient
{
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/SqlDataReader/*' />
public class SqlDataReader : DbDataReader, IDataReader
public class SqlDataReader : DbDataReader, IDataReader, IDbColumnSchemaGenerator
MichelZ marked this conversation as resolved.
Show resolved Hide resolved
{
private enum ALTROWSTATUS
{
Expand Down Expand Up @@ -74,6 +75,7 @@ internal class SharedState
private CommandBehavior _commandBehavior;

private static int s_objectTypeCount; // EventSource Counter
private static readonly ReadOnlyCollection<DbColumn> s_emptySchema = new ReadOnlyCollection<DbColumn>(Array.Empty<DbColumn>());
internal readonly int ObjectID = Interlocked.Increment(ref s_objectTypeCount);


Expand Down Expand Up @@ -6360,5 +6362,73 @@ private void SwitchToAsyncWithoutSnapshot()
_stateObj._asyncReadWithoutSnapshot = true;
}

}// SqlDataReader
}// namespace
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetColumnSchema/*' />
public ReadOnlyCollection<DbColumn> 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<DbColumn> 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<DbColumn>(columnSchema);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageReference Include="Microsoft.Bcl.Cryptography" Version="$(MicrosoftBclCryptographyVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
<PackageReference Include="System.Data.Common" Version="$(SystemDataCommonVersion)" Condition="'$(TargetFramework)' == 'net462'" />
MichelZ marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="$(SystemRuntimeInteropServicesRuntimeInformationVersion)" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="$(SystemSecurityCryptographyPkcsVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ internal sealed partial class _SqlMetaDataSet

internal DataTable schemaTable;
private readonly _SqlMetaData[] _metaDataArray;
#if !NETFRAMEWORK
internal ReadOnlyCollection<DbColumn> dbColumnSchema;
#endif

private int _hiddenColumnCount;
private int[] _visibleColumnMap;
Expand All @@ -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;
MichelZ marked this conversation as resolved.
Show resolved Hide resolved
#endif

if (original._metaDataArray == null)
{
_metaDataArray = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
MichelZ marked this conversation as resolved.
Show resolved Hide resolved
{
Expand All @@ -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<DbColumn> columns = reader.GetColumnSchema();
ReadOnlyCollection<System.Data.Common.DbColumn> 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];
Expand Down
1 change: 1 addition & 0 deletions tools/props/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<SystemMemoryVersion>4.5.5</SystemMemoryVersion>
<SystemTextEncodingsWebVersion>6.0.0</SystemTextEncodingsWebVersion>
<SystemTextJsonVersion>6.0.10</SystemTextJsonVersion>
<SystemDataCommonVersion>4.3.0</SystemDataCommonVersion>
</PropertyGroup>
<!-- NetFx and NetCore project dependencies -->
<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions tools/specs/Microsoft.Data.SqlClient.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ When using NuGet 3.x this package requires at least version 3.4.</description>
<dependency id="System.Buffers" version="4.5.1" />
<dependency id="System.Text.Encodings.Web" version="6.0.0" />
<dependency id="System.Text.Json" version="6.0.10" />
<dependency id="System.Data.Common" version="4.3.0" />
<dependency id="System.Security.Cryptography.Pkcs" version="8.0.1"/>
<dependency id="Microsoft.Bcl.Cryptography" version="8.0.0"/>
</group>
Expand Down
Loading