Skip to content

Commit 12c64ab

Browse files
committed
Extract DbColumn to its own file.
1 parent f218646 commit 12c64ab

File tree

2 files changed

+72
-78
lines changed

2 files changed

+72
-78
lines changed

src/MySqlConnector/MySqlDbColumn.cs

Lines changed: 40 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,51 @@
44
using MySqlConnector.Protocol.Payloads;
55
using MySqlConnector.Protocol.Serialization;
66

7-
#if NET461
8-
#pragma warning disable CA1716 // Don't use reserved language keywords
9-
#pragma warning disable SA1402 // File may only contain a single type
10-
#pragma warning disable SA1403 // File may only contain a single namespace
11-
#pragma warning disable SA1649 // File name should match first type name
12-
namespace System.Data.Common
13-
{
14-
public abstract class DbColumn
15-
{
16-
public bool? AllowDBNull { get; protected set; }
17-
public string? BaseCatalogName { get; protected set; }
18-
public string? BaseColumnName { get; protected set; }
19-
public string? BaseSchemaName { get; protected set; }
20-
public string? BaseServerName { get; protected set; }
21-
public string? BaseTableName { get; protected set; }
22-
public string ColumnName { get; protected set; } = "";
23-
public int? ColumnOrdinal { get; protected set; }
24-
public int? ColumnSize { get; protected set; }
25-
public bool? IsAliased { get; protected set; }
26-
public bool? IsAutoIncrement { get; protected set; }
27-
public bool? IsExpression { get; protected set; }
28-
public bool? IsHidden { get; protected set; }
29-
public bool? IsIdentity { get; protected set; }
30-
public bool? IsKey { get; protected set; }
31-
public bool? IsLong { get; protected set; }
32-
public bool? IsReadOnly { get; protected set; }
33-
public bool? IsUnique { get; protected set; }
34-
public int? NumericPrecision { get; protected set; }
35-
public int? NumericScale { get; protected set; }
36-
public string? UdtAssemblyQualifiedName { get; protected set; }
37-
public Type? DataType { get; protected set; }
38-
public string? DataTypeName { get; protected set; }
39-
public virtual object? this[string property] => null;
40-
}
41-
}
42-
#endif
7+
namespace MySqlConnector;
438

44-
namespace MySqlConnector
9+
public sealed class MySqlDbColumn : DbColumn
4510
{
46-
public sealed class MySqlDbColumn : System.Data.Common.DbColumn
11+
internal MySqlDbColumn(int ordinal, ColumnDefinitionPayload column, bool allowZeroDateTime, MySqlDbType mySqlDbType)
4712
{
48-
internal MySqlDbColumn(int ordinal, ColumnDefinitionPayload column, bool allowZeroDateTime, MySqlDbType mySqlDbType)
49-
{
50-
var columnTypeMetadata = TypeMapper.Instance.GetColumnTypeMetadata(mySqlDbType);
13+
var columnTypeMetadata = TypeMapper.Instance.GetColumnTypeMetadata(mySqlDbType);
5114

52-
var type = columnTypeMetadata.DbTypeMapping.ClrType;
53-
var columnSize = type == typeof(string) || type == typeof(Guid) ?
54-
column.ColumnLength / ProtocolUtility.GetBytesPerCharacter(column.CharacterSet) :
55-
column.ColumnLength;
15+
var type = columnTypeMetadata.DbTypeMapping.ClrType;
16+
var columnSize = type == typeof(string) || type == typeof(Guid) ?
17+
column.ColumnLength / ProtocolUtility.GetBytesPerCharacter(column.CharacterSet) :
18+
column.ColumnLength;
5619

57-
AllowDBNull = (column.ColumnFlags & ColumnFlags.NotNull) == 0;
58-
BaseCatalogName = null;
59-
BaseColumnName = column.PhysicalName;
60-
BaseSchemaName = column.SchemaName;
61-
BaseTableName = column.PhysicalTable;
62-
ColumnName = column.Name;
63-
ColumnOrdinal = ordinal;
64-
ColumnSize = columnSize > int.MaxValue ? int.MaxValue : unchecked((int) columnSize);
65-
DataType = (allowZeroDateTime && type == typeof(DateTime)) ? typeof(MySqlDateTime) : type;
66-
DataTypeName = columnTypeMetadata.SimpleDataTypeName;
67-
if (mySqlDbType == MySqlDbType.String)
68-
DataTypeName += string.Format(CultureInfo.InvariantCulture, "({0})", columnSize);
69-
IsAliased = column.PhysicalName != column.Name;
70-
IsAutoIncrement = (column.ColumnFlags & ColumnFlags.AutoIncrement) != 0;
71-
IsExpression = false;
72-
IsHidden = false;
73-
IsKey = (column.ColumnFlags & ColumnFlags.PrimaryKey) != 0;
74-
IsLong = column.ColumnLength > 255 &&
75-
((column.ColumnFlags & ColumnFlags.Blob) != 0 || column.ColumnType is ColumnType.TinyBlob or ColumnType.Blob or ColumnType.MediumBlob or ColumnType.LongBlob);
76-
IsReadOnly = false;
77-
IsUnique = (column.ColumnFlags & ColumnFlags.UniqueKey) != 0;
78-
if (column.ColumnType is ColumnType.Decimal or ColumnType.NewDecimal)
79-
{
80-
NumericPrecision = (int) column.ColumnLength;
81-
if ((column.ColumnFlags & ColumnFlags.Unsigned) == 0)
82-
NumericPrecision--;
83-
if (column.Decimals > 0)
84-
NumericPrecision--;
85-
}
86-
NumericScale = column.Decimals;
87-
ProviderType = mySqlDbType;
20+
AllowDBNull = (column.ColumnFlags & ColumnFlags.NotNull) == 0;
21+
BaseCatalogName = null;
22+
BaseColumnName = column.PhysicalName;
23+
BaseSchemaName = column.SchemaName;
24+
BaseTableName = column.PhysicalTable;
25+
ColumnName = column.Name;
26+
ColumnOrdinal = ordinal;
27+
ColumnSize = columnSize > int.MaxValue ? int.MaxValue : unchecked((int) columnSize);
28+
DataType = (allowZeroDateTime && type == typeof(DateTime)) ? typeof(MySqlDateTime) : type;
29+
DataTypeName = columnTypeMetadata.SimpleDataTypeName;
30+
if (mySqlDbType == MySqlDbType.String)
31+
DataTypeName += string.Format(CultureInfo.InvariantCulture, "({0})", columnSize);
32+
IsAliased = column.PhysicalName != column.Name;
33+
IsAutoIncrement = (column.ColumnFlags & ColumnFlags.AutoIncrement) != 0;
34+
IsExpression = false;
35+
IsHidden = false;
36+
IsKey = (column.ColumnFlags & ColumnFlags.PrimaryKey) != 0;
37+
IsLong = column.ColumnLength > 255 &&
38+
((column.ColumnFlags & ColumnFlags.Blob) != 0 || column.ColumnType is ColumnType.TinyBlob or ColumnType.Blob or ColumnType.MediumBlob or ColumnType.LongBlob);
39+
IsReadOnly = false;
40+
IsUnique = (column.ColumnFlags & ColumnFlags.UniqueKey) != 0;
41+
if (column.ColumnType is ColumnType.Decimal or ColumnType.NewDecimal)
42+
{
43+
NumericPrecision = (int) column.ColumnLength;
44+
if ((column.ColumnFlags & ColumnFlags.Unsigned) == 0)
45+
NumericPrecision--;
46+
if (column.Decimals > 0)
47+
NumericPrecision--;
8848
}
89-
90-
public MySqlDbType ProviderType { get; }
49+
NumericScale = column.Decimals;
50+
ProviderType = mySqlDbType;
9151
}
52+
53+
public MySqlDbType ProviderType { get; }
9254
}

src/MySqlConnector/Shims/DbColumn.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#if NET461
2+
#pragma warning disable CA1716 // Don't use reserved language keywords
3+
namespace System.Data.Common;
4+
5+
public abstract class DbColumn
6+
{
7+
public bool? AllowDBNull { get; protected set; }
8+
public string? BaseCatalogName { get; protected set; }
9+
public string? BaseColumnName { get; protected set; }
10+
public string? BaseSchemaName { get; protected set; }
11+
public string? BaseServerName { get; protected set; }
12+
public string? BaseTableName { get; protected set; }
13+
public string ColumnName { get; protected set; } = "";
14+
public int? ColumnOrdinal { get; protected set; }
15+
public int? ColumnSize { get; protected set; }
16+
public bool? IsAliased { get; protected set; }
17+
public bool? IsAutoIncrement { get; protected set; }
18+
public bool? IsExpression { get; protected set; }
19+
public bool? IsHidden { get; protected set; }
20+
public bool? IsIdentity { get; protected set; }
21+
public bool? IsKey { get; protected set; }
22+
public bool? IsLong { get; protected set; }
23+
public bool? IsReadOnly { get; protected set; }
24+
public bool? IsUnique { get; protected set; }
25+
public int? NumericPrecision { get; protected set; }
26+
public int? NumericScale { get; protected set; }
27+
public string? UdtAssemblyQualifiedName { get; protected set; }
28+
public Type? DataType { get; protected set; }
29+
public string? DataTypeName { get; protected set; }
30+
public virtual object? this[string property] => null;
31+
}
32+
#endif

0 commit comments

Comments
 (0)