|
29 | 29 | import org.junit.Test; |
30 | 30 |
|
31 | 31 | import java.math.BigDecimal; |
| 32 | +import java.time.Instant; |
32 | 33 | import java.util.Arrays; |
33 | 34 | import java.util.List; |
34 | 35 |
|
@@ -602,6 +603,40 @@ public void testInvalidInsertStatement(TestContext context) { |
602 | 603 | }); |
603 | 604 | } |
604 | 605 |
|
| 606 | + @Test |
| 607 | + public void testInstant(TestContext context) { |
| 608 | + Async async = context.async(); |
| 609 | + client.getConnection(ar -> { |
| 610 | + ensureSuccess(context, ar); |
| 611 | + conn = ar.result(); |
| 612 | + conn.execute("DROP TABLE IF EXISTS test_table", ar1 -> { |
| 613 | + ensureSuccess(context, ar1); |
| 614 | + conn.execute("CREATE TABLE test_table (instant TIMESTAMP)", ar2 -> { |
| 615 | + ensureSuccess(context, ar2); |
| 616 | + Instant now = Instant.now(); |
| 617 | + conn.queryWithParams("INSERT INTO test_table (instant) VALUES (?)", new JsonArray().add(now), ar3 -> { |
| 618 | + ensureSuccess(context, ar3); |
| 619 | + conn.query("SELECT instant FROM test_table", ar4 -> { |
| 620 | + ensureSuccess(context, ar4); |
| 621 | + // timestamps with out time zone are returned as strings, so we must compare to the original instant |
| 622 | + // ignoring the timezone offset (meaning ignore everything after char 23) |
| 623 | + compareInstantStrings( |
| 624 | + context, |
| 625 | + ar4.result().getResults().get(0).getString(0), |
| 626 | + now.toString().substring(0, 23) |
| 627 | + ); |
| 628 | + async.complete(); |
| 629 | + }); |
| 630 | + }); |
| 631 | + }); |
| 632 | + }); |
| 633 | + }); |
| 634 | + } |
| 635 | + |
| 636 | + protected void compareInstantStrings(TestContext context, String result, String expected) { |
| 637 | + context.assertEquals(result, expected); |
| 638 | + } |
| 639 | + |
605 | 640 | protected void setSqlModeIfPossible(Handler<Void> handler) { |
606 | 641 | handler.handle(null); |
607 | 642 | } |
|
0 commit comments