Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add SqlFacetAttribute #32245

Merged
merged 4 commits into from
Sep 18, 2018
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
13 changes: 13 additions & 0 deletions src/System.Data.SqlClient/ref/System.Data.SqlClient.NetCoreApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------

namespace Microsoft.SqlServer.Server
{
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue | System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=false)]
public partial class SqlFacetAttribute : System.Attribute
{
public SqlFacetAttribute() { }
public bool IsFixedLength { get { throw null; } set { } }
public bool IsNullable { get { throw null; } set { } }
public int MaxSize { get { throw null; } set { } }
public int Precision { get { throw null; } set { } }
public int Scale { get { throw null; } set { } }
}
}
namespace System.Data.SqlClient
{
public partial class SqlDataReader : System.Data.Common.IDbColumnSchemaGenerator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Microsoft.SqlServer.Server
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this file is located under System/Data/Sql directory in .NetFramework. Should we move this to the same location?
https://referencesource.microsoft.com/#System.Data/System/Data/Sql/SqlFacetAttribute.cs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CoreFX we try to make the folder hierarchy follow the namespace, as I did here. For example we have src\System.Data.SqlClient\src\Microsoft\SqlServer\Server\SmiMetaData.cs for a type Microsoft.SqlServer.Server.SmiMetadata

public class SqlFacetAttribute : Attribute
{
/// <summary>
/// Is this a fixed size field?
/// </summary>
public bool IsFixedLength
{
get;
set;
}

/// <summary>
/// The maximum size of the field (in bytes or characters depending on the field type)
/// or -1 if the size can be unlimited.
/// </summary>
public int MaxSize
{
get;
set;
}

/// <summary>
/// Precision, only valid for numeric types.
/// </summary>
public int Precision
{
get;
set;
}

/// <summary>
/// Scale, only valid for numeric types.
/// </summary>
public int Scale
{
get;
set;
}

/// <summary>
/// Is this field nullable?
/// </summary>
public bool IsNullable
{
get;
set;
}
}
}
1 change: 1 addition & 0 deletions src/System.Data.SqlClient/src/System.Data.SqlClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</ItemGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' AND '$(OSGroup)' != 'AnyOS' AND '$(TargetsNetCoreApp)' == 'true'">
<Compile Include="System\Data\SqlClient\PoolBlockingPeriod.cs" />
<Compile Include="Microsoft\SqlServer\Server\SqlFacetAttribute.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' AND '$(OSGroup)' != 'AnyOS'">
<Compile Include="Microsoft\SqlServer\Server\ITypedGetters.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<BuildConfigurations>
netstandard-Unix;
netstandard-Windows_NT;
netcoreapp-Unix;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the netcoreapp configurations OS specific because otherwise if you just do "msbuild" it will pick the netstandard configurations, which is probably not what you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick look at the project file I'm not sure why the netstandard configuration is OS specific but I wouldn't expect the neither of them to need to be OS specific.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. @afsanehr if you don't know of a reason why these tests could be OS specific, I will remove the OS suffixes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason why they are OS specific is because the AnyOS implementation assembly throws platform not supported exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK

netcoreapp-Windows_NT;
</BuildConfigurations>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.SqlServer.Server;
using Xunit;

namespace System.Data.SqlClient.Tests
{
public class SqlFacetAttributeTests
{
[Fact]
public void Basic()
{
var attrib = new SqlFacetAttribute();

attrib.IsFixedLength = true;
attrib.IsNullable = false;
attrib.MaxSize = 123;
attrib.Precision = 234;
attrib.Scale = 345;

Assert.Equal(true, attrib.IsFixedLength);
Assert.Equal(false, attrib.IsNullable);
Assert.Equal(123, attrib.MaxSize);
Assert.Equal(234, attrib.Precision);
Assert.Equal(345, attrib.Scale);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<Compile Include="TestTdsServer.cs" />
<Compile Include="..\ManualTests\DataCommon\DataTestUtility.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<Compile Include="SqlFacetAttributeTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ManualTests\SQL\UdtTest\UDTs\Address\Address.csproj">
<Project>{d1392b54-998a-4f27-bc17-4ce149117bcc}</Project>
Expand Down