Skip to content

Commit 544ed7c

Browse files
committed
Fix for Bug#97724 (30570721), Contribution: Allow \'3.\' formatted numbers.
1 parent 4234248 commit 544ed7c

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
Version 8.0.20
55

6+
- Fix for Bug#97724 (30570721), Contribution: Allow \'3.\' formatted numbers.
7+
Thanks to Nick Pollett for his contribution.
8+
69
- Fix for Bug#98536 (30877755), SIMPLEDATEFORMAT COULD CACHE A WRONG CALENDAR.
710

811
- Fix for Bug#91112 (28125069), AGAIN WRONG JAVA.SQL.DATE.

src/main/core-impl/java/com/mysql/cj/result/AbstractNumericValueFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -52,7 +52,7 @@ public T createFromBytes(byte[] bytes, int offset, int length, Field f) {
5252
String s = StringUtils.toString(bytes, offset, length, f.getEncoding());
5353
byte[] newBytes = s.getBytes();
5454

55-
if (s.contains("e") || s.contains("E") || s.matches("-?(\\d+)?\\.\\d+")) {
55+
if (s.contains("e") || s.contains("E") || s.matches("-?\\d*\\.\\d*")) {
5656
// floating point
5757
return createFromDouble(MysqlTextValueDecoder.getDouble(newBytes, 0, newBytes.length));
5858
} else if (s.matches("-?\\d+")) {

src/main/core-impl/java/com/mysql/cj/result/BooleanValueFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -102,7 +102,7 @@ public Boolean createFromBytes(byte[] bytes, int offset, int length, Field f) {
102102
return createFromLong(1);
103103
} else if (s.equalsIgnoreCase("N") || s.equalsIgnoreCase("false")) {
104104
return createFromLong(0);
105-
} else if (s.contains("e") || s.contains("E") || s.matches("-?(\\d+)?\\.\\d+")) {
105+
} else if (s.contains("e") || s.contains("E") || s.matches("-?\\d*\\.\\d*")) {
106106
// floating point
107107
return createFromDouble(MysqlTextValueDecoder.getDouble(newBytes, 0, newBytes.length));
108108
} else if (s.matches("-?\\d+")) {

src/test/java/testsuite/regression/ResultSetRegressionTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7319,4 +7319,30 @@ public void testBug30474158() throws Exception {
73197319
assertEquals("testBug30474158", this.rs.getString(1));
73207320
}
73217321
}
7322+
7323+
/**
7324+
* Tests fix for Bug#97724 (30570721), Contribution: Allow \'3.\' formatted numbers.
7325+
*/
7326+
public void testBug97724() throws Exception {
7327+
createTable("testBug97724", "(data VARCHAR(100))");
7328+
assertEquals(4, this.stmt.executeUpdate("INSERT INTO testBug97724 VALUES ('0.0'), ('.1'), ('2.'), ('3.3')"));
7329+
this.rs = this.stmt.executeQuery("SELECT * FROM testBug97724");
7330+
assertTrue(this.rs.next());
7331+
assertFalse(this.rs.getBoolean(1));
7332+
assertEquals(0, this.rs.getInt(1));
7333+
assertEquals(0.0d, this.rs.getDouble(1));
7334+
assertTrue(this.rs.next());
7335+
assertTrue(this.rs.getBoolean(1));
7336+
assertEquals(0, this.rs.getInt(1));
7337+
assertEquals(0.1d, this.rs.getDouble(1));
7338+
assertTrue(this.rs.next());
7339+
assertTrue(this.rs.getBoolean(1));
7340+
assertEquals(2, this.rs.getInt(1));
7341+
assertEquals(2.0d, this.rs.getDouble(1));
7342+
assertTrue(this.rs.next());
7343+
assertTrue(this.rs.getBoolean(1));
7344+
assertEquals(3, this.rs.getInt(1));
7345+
assertEquals(3.3d, this.rs.getDouble(1));
7346+
assertFalse(this.rs.next());
7347+
}
73227348
}

0 commit comments

Comments
 (0)