File tree Expand file tree Collapse file tree 3 files changed +39
-17
lines changed Expand file tree Collapse file tree 3 files changed +39
-17
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ internal MySqlDecimal(string value)
46
46
throw new FormatException ( $ "Could not parse the value as a MySqlDecimal: { value } ") ;
47
47
}
48
48
49
- private static readonly Regex s_pattern = new ( @"^-?([1-9][ 0-9]*|0 )(\.([0-9]+))?$" ) ;
49
+ private static readonly Regex s_pattern = new ( @"^-?([0-9]+ )(\.([0-9]+))?$" ) ;
50
50
51
51
private readonly string m_value ;
52
52
}
Original file line number Diff line number Diff line change @@ -514,6 +514,40 @@ public void ReadMySqlDecimalUsingReader(bool prepare)
514
514
#endif
515
515
}
516
516
517
+ [ Theory ]
518
+ [ InlineData ( false ) ]
519
+ [ InlineData ( true ) ]
520
+ public void ReadMySqlDecimalZeroFill ( bool prepare )
521
+ {
522
+ using MySqlConnection connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
523
+ connection . Open ( ) ;
524
+ connection . Execute ( """
525
+ drop table if exists mysql_decimal_zerofill;
526
+ create table mysql_decimal_zerofill(rowid integer not null primary key auto_increment, value decimal(20, 10) zerofill);
527
+ insert into mysql_decimal_zerofill(value) values(0),(1),(0.1);
528
+ """ ) ;
529
+
530
+ using var cmd = connection . CreateCommand ( ) ;
531
+ cmd . CommandText = @"select value from mysql_decimal_zerofill order by rowid;" ;
532
+ if ( prepare )
533
+ cmd . Prepare ( ) ;
534
+ using var reader = cmd . ExecuteReader ( ) ;
535
+
536
+ Assert . True ( reader . Read ( ) ) ;
537
+ Assert . Equal ( "0000000000.0000000000" , reader . GetMySqlDecimal ( "value" ) . ToString ( ) ) ;
538
+ Assert . Equal ( 0m , reader . GetDecimal ( 0 ) ) ;
539
+
540
+ Assert . True ( reader . Read ( ) ) ;
541
+ Assert . Equal ( "0000000001.0000000000" , reader . GetMySqlDecimal ( "value" ) . ToString ( ) ) ;
542
+ Assert . Equal ( 1m , reader . GetDecimal ( 0 ) ) ;
543
+
544
+ Assert . True ( reader . Read ( ) ) ;
545
+ Assert . Equal ( "0000000000.1000000000" , reader . GetMySqlDecimal ( "value" ) . ToString ( ) ) ;
546
+ Assert . Equal ( 0.1m , reader . GetDecimal ( 0 ) ) ;
547
+
548
+ Assert . False ( reader . Read ( ) ) ;
549
+ }
550
+
517
551
[ Theory ]
518
552
[ InlineData ( false ) ]
519
553
[ InlineData ( true ) ]
Original file line number Diff line number Diff line change @@ -30,20 +30,6 @@ public void TestToDecimal()
30
30
Assert . Equal ( doubleVal , mySqlDecimal . Value ) ;
31
31
}
32
32
33
- [ Fact ]
34
- public void TestInvalidFormatWithDecimalPostive ( )
35
- {
36
- var invalidValue = "0323.323" ;
37
- Assert . Throws < FormatException > ( ( ) => new MySqlDecimal ( invalidValue ) ) ;
38
- }
39
-
40
- [ Fact ]
41
- public void TestInvalidFormatWithDecimalNegative ( )
42
- {
43
- var invalidValue = "-0323.323" ;
44
- Assert . Throws < FormatException > ( ( ) => new MySqlDecimal ( invalidValue ) ) ;
45
- }
46
-
47
33
[ Fact ]
48
34
public void TestValidFormatWithDecimalNegative68Length ( )
49
35
{
@@ -109,6 +95,10 @@ public void TestValidFormatWithDecimalNegative67Length()
109
95
[ InlineData ( "-0.1" ) ]
110
96
[ InlineData ( "1.0" ) ]
111
97
[ InlineData ( "1.23" ) ]
98
+ [ InlineData ( "00" ) ]
99
+ [ InlineData ( "01" ) ]
100
+ [ InlineData ( "0323.323" ) ]
101
+ [ InlineData ( "-0323.323" ) ]
112
102
[ InlineData ( "12345678901234567890123456789012345678901234567890123456789012345" ) ]
113
103
[ InlineData ( "-12345678901234567890123456789012345678901234567890123456789012345" ) ]
114
104
[ InlineData ( "12345678901234567890123456789012345.012345678901234567890123456789" ) ]
@@ -120,8 +110,6 @@ public void ValidDecimalValues(string input) =>
120
110
[ InlineData ( "" ) ]
121
111
[ InlineData ( "-0" ) ]
122
112
[ InlineData ( "-0.0" ) ]
123
- [ InlineData ( "00" ) ]
124
- [ InlineData ( "01" ) ]
125
113
[ InlineData ( "123456789012345678901234567890123456789012345678901234567890123456" ) ]
126
114
[ InlineData ( "-123456789012345678901234567890123456789012345678901234567890123456" ) ]
127
115
[ InlineData ( "123456789012345678901234567890123456.012345678901234567890123456789" ) ]
You can’t perform that action at this time.
0 commit comments