Skip to content

Commit ac9c71d

Browse files
committed
Fix incorrect NumericPrecision. Fixes #356
1 parent 6b7b3f8 commit ac9c71d

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

docs/content/tutorials/migrating-from-connector-net.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ property doesn't reference the active transaction. See [#333](https://github.com
9595
* [#86263](https://bugs.mysql.com/bug.php?id=86263): Transaction isolation level affects all transactions in session
9696
* [#87868](https://bugs.mysql.com/bug.php?id=87868): `ColumnSize` in schema table is incorrect for `CHAR(36)` and `BLOB` columns
9797
* [#87876](https://bugs.mysql.com/bug.php?id=87876): `IsLong` is schema table is incorrect for `LONGTEXT` and `LONGBLOB` columns
98+
* [#88058](https://bugs.mysql.com/bug.php?id=88058): `decimal(n, 0)` has wrong `NumericPrecision`

src/MySqlConnector/MySqlClient/MySqlDbColumn.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ internal MySqlDbColumn(int ordinal, ColumnDefinitionPayload column, Type type, s
3535
IsReadOnly = false;
3636
IsUnique = (column.ColumnFlags & ColumnFlags.UniqueKey) != 0;
3737
if (column.ColumnType == ColumnType.Decimal || column.ColumnType == ColumnType.NewDecimal)
38-
NumericPrecision = (int) (column.ColumnLength - 2 + ((column.ColumnFlags & ColumnFlags.Unsigned) != 0 ? 1 : 0));
38+
{
39+
NumericPrecision = (int) column.ColumnLength;
40+
if ((column.ColumnFlags & ColumnFlags.Unsigned) == 0)
41+
NumericPrecision--;
42+
if (column.Decimals > 0)
43+
NumericPrecision--;
44+
}
3945
NumericScale = column.Decimals;
4046
ProviderType = (int) column.ColumnType;
4147
}

tests/SideBySide/DataTypes.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,33 @@ public void InsertLargeBlobSync(string column, int size)
648648
[InlineData("Timestamp", "datatypes_times", 26, typeof(DateTime), "N", 0, 6)]
649649
[InlineData("Time", "datatypes_times", 17, typeof(TimeSpan), "N", 0, 6)]
650650
[InlineData("Year", "datatypes_times", 4, typeof(int), "N", 0, 0)]
651-
public void GetSchemaTable(string column, string table, int columnSize, Type dataType, string flags, int precision, int scale)
651+
public void GetSchemaTable(string column, string table, int columnSize, Type dataType, string flags, int precision, int scale) =>
652+
DoGetSchemaTable(column, table, columnSize, dataType, flags, precision, scale);
653+
654+
[Theory]
655+
[InlineData("`decimal-type` decimal(10,0) NOT NULL", "decimal-type", 11, typeof(decimal), "", 10, 0
656+
#if BASELINE
657+
, Skip = "https://bugs.mysql.com/bug.php?id=88058"
658+
#endif
659+
)]
660+
[InlineData("`decimal-type` decimal(10,1) NOT NULL", "decimal-type", 12, typeof(decimal), "", 10, 1)]
661+
[InlineData("`decimal-type` decimal(10,0) UNSIGNED NOT NULL", "decimal-type", 10, typeof(decimal), "", 10, 0
662+
#if BASELINE
663+
, Skip = "https://bugs.mysql.com/bug.php?id=88058"
664+
#endif
665+
)]
666+
[InlineData("`decimal-type` decimal(10,1) UNSIGNED NOT NULL", "decimal-type", 11, typeof(decimal), "", 10, 1)]
667+
[InlineData("`decimal-type` decimal(65,30) NOT NULL", "decimal-type", 67, typeof(decimal), "", 65, 30)]
668+
[InlineData("`decimal-type` decimal(1,1) NOT NULL", "decimal-type", 3, typeof(decimal), "", 1, 1)]
669+
public void GetSchemaTableForNewColumn(string createColumn, string column, int columnSize, Type dataType, string flags, int precision, int scale)
670+
{
671+
m_database.Connection.Execute($@"drop table if exists schema_table;
672+
create table schema_table({createColumn});");
673+
674+
DoGetSchemaTable(column, "schema_table", columnSize, dataType, flags, precision, scale);
675+
}
676+
677+
private void DoGetSchemaTable(string column, string table, int columnSize, Type dataType, string flags, int precision, int scale)
652678
{
653679
if (table == "datatypes_json_core" && !AppConfig.SupportsJson)
654680
return;

0 commit comments

Comments
 (0)