|
4 | 4 | using MySqlConnector.Protocol.Payloads;
|
5 | 5 | using MySqlConnector.Protocol.Serialization;
|
6 | 6 |
|
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; |
43 | 8 |
|
44 |
| -namespace MySqlConnector |
| 9 | +public sealed class MySqlDbColumn : DbColumn |
45 | 10 | {
|
46 |
| - public sealed class MySqlDbColumn : System.Data.Common.DbColumn |
| 11 | + internal MySqlDbColumn(int ordinal, ColumnDefinitionPayload column, bool allowZeroDateTime, MySqlDbType mySqlDbType) |
47 | 12 | {
|
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); |
51 | 14 |
|
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; |
56 | 19 |
|
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--; |
88 | 48 | }
|
89 |
| - |
90 |
| - public MySqlDbType ProviderType { get; } |
| 49 | + NumericScale = column.Decimals; |
| 50 | + ProviderType = mySqlDbType; |
91 | 51 | }
|
| 52 | + |
| 53 | + public MySqlDbType ProviderType { get; } |
92 | 54 | }
|
0 commit comments