|
28 | 28 | import io.vertx.ext.unit.TestContext; |
29 | 29 | import org.junit.Test; |
30 | 30 |
|
| 31 | +import java.math.BigDecimal; |
| 32 | +import java.util.Arrays; |
31 | 33 | import java.util.List; |
32 | 34 |
|
33 | 35 | public abstract class SQLTestBase extends AbstractTestBase { |
@@ -459,6 +461,37 @@ public void testDateValueSelection(TestContext context) { |
459 | 461 | }); |
460 | 462 | } |
461 | 463 |
|
| 464 | + @Test |
| 465 | + public void testDecimalFields(TestContext context) { |
| 466 | + Async async = context.async(); |
| 467 | + client.getConnection(arConn -> { |
| 468 | + ensureSuccess(context, arConn); |
| 469 | + conn = arConn.result(); |
| 470 | + conn.execute("DROP TABLE IF EXISTS test_table", arDrop -> { |
| 471 | + ensureSuccess(context, arDrop); |
| 472 | + conn.execute("CREATE TABLE test_table (id INT, some_decimal DECIMAL(65,6))", arCreate -> { |
| 473 | + ensureSuccess(context, arCreate); |
| 474 | + conn.execute("INSERT INTO test_table (id, some_decimal) VALUES " + |
| 475 | + "(1, 43210987654321098765432109876543210987654321098765432109871.123451)," + |
| 476 | + "(2, 43210987654321098765432109876543210987654321098765432109872.123452)," + |
| 477 | + "(3, 43210987654321098765432109876543210987654321098765432109873.123453)", arInsert -> { |
| 478 | + ensureSuccess(context, arInsert); |
| 479 | + conn.query("SELECT some_decimal FROM test_table ORDER BY id", arQuery -> { |
| 480 | + ensureSuccess(context, arQuery); |
| 481 | + ResultSet res = arQuery.result(); |
| 482 | + context.assertEquals(new BigDecimal("43210987654321098765432109876543210987654321098765432109871.123451"), new BigDecimal(res.getRows().get(0).getString("some_decimal"))); |
| 483 | + context.assertEquals(new BigDecimal("43210987654321098765432109876543210987654321098765432109872.123452"), new BigDecimal(res.getResults().get(1).getString(0))); |
| 484 | + context.assertEquals(new BigDecimal("43210987654321098765432109876543210987654321098765432109873.123453"), new BigDecimal(res.getRows().get(2).getString("some_decimal"))); |
| 485 | + // This will convert both (big) numbers into a double which will loose some information |
| 486 | + context.assertEquals(43210987654321098765432109876543210987654321098765432109873.123453, Double.parseDouble(res.getRows().get(2).getString("some_decimal"))); |
| 487 | + async.complete(); |
| 488 | + }); |
| 489 | + }); |
| 490 | + }); |
| 491 | + }); |
| 492 | + }); |
| 493 | + } |
| 494 | + |
462 | 495 | protected void setSqlModeIfPossible(Handler<Void> handler) { |
463 | 496 | handler.handle(null); |
464 | 497 | } |
|
0 commit comments