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

MySqlDecimal does not support ZEROFILL column #1354

Closed
bgrainger opened this issue Aug 16, 2023 · 2 comments
Closed

MySqlDecimal does not support ZEROFILL column #1354

bgrainger opened this issue Aug 16, 2023 · 2 comments
Labels
Milestone

Comments

@bgrainger
Copy link
Member

Software versions
MySqlConnector version: 2.2.7
Server type (MySQL, MariaDB, Aurora, etc.) and version: MySQL 8.0
.NET version: 7.0

Describe the bug

MySqlDataReader.GetMySqlDecimal can't read a value from a column with the ZEROFILL attribute.

Exception

FormatException: Could not parse the value as a MySqlDecimal: 0000000000.0000000000
   at MySqlConnector.MySqlDecimal..ctor(String value) in C:\Code\MySql\MySqlConnector\src\MySqlConnector\MySqlDecimal.cs:line 46
   at MySqlConnector.Core.Row.GetMySqlDecimal(Int32 ordinal) in C:\Code\MySql\MySqlConnector\src\MySqlConnector\Core\Row.cs:line 415
   at MySqlConnector.MySqlDataReader.GetMySqlDecimal(Int32 ordinal) in C:\Code\MySql\MySqlConnector\src\MySqlConnector\MySqlDataReader.cs:line 276
   at UserQuery.Main(), line 33

Code sample

drop table if exists dectest;
create table dectest(value decimal(20,10) zerofill);
insert into dectest(value) values(0),(1),(0.1);
using var cmd = new MySqlCommand("select value from dectest", connection);
using var reader = cmd.ExecuteReader();
while (reader.Read())
    reader.GetMySqlDecimal(0).Dump();

Expected behavior

Reads the column value as a MySqlDecimal.

Additional context

Reported here: #1075 (comment)

@alexr17
Copy link

alexr17 commented Aug 21, 2023

If you wanted to parse these zerofilled decimals using .NET primitives and truncate it, that's possible, but from testing we could only support precision up to about 29/30 digits.

@bgrainger
Copy link
Member Author

That's why the MySqlDecimal type exists: to store MySQL DECIMAL values that fall outside the range of a System.Decimal.

@bgrainger bgrainger added this to the 2.3 milestone Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants