Skip to content

Commit f37e773

Browse files
authored
Merge pull request #54 from vert-x3/issues/issue-53
Fixes #53: TS WITHOUT TZ are returned as String, TS WITH TZ are conve…
2 parents 18e90d4 + 09e8153 commit f37e773

File tree

7 files changed

+56
-17
lines changed

7 files changed

+56
-17
lines changed

src/main/asciidoc/groovy/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.3.2 (the client)
18+
* vertx-mysql-postgresql-client 3.4.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.3.2</version>
36+
<version>3.4.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.2'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.4.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions

src/main/asciidoc/java/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.3.2 (the client)
18+
* vertx-mysql-postgresql-client 3.4.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.3.2</version>
36+
<version>3.4.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.2'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.4.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions

src/main/asciidoc/js/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.3.2 (the client)
18+
* vertx-mysql-postgresql-client 3.4.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.3.2</version>
36+
<version>3.4.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.2'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.4.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions

src/main/asciidoc/ruby/index.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.3.2 (the client)
18+
* vertx-mysql-postgresql-client 3.4.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.3.2</version>
36+
<version>3.4.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.2'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.4.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions

src/main/java/io/vertx/ext/asyncsql/impl/AsyncSQLConnectionImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929
import io.vertx.ext.sql.TransactionIsolation;
3030
import io.vertx.ext.sql.UpdateResult;
3131
import org.joda.time.DateTime;
32+
import org.joda.time.DateTimeZone;
3233
import org.joda.time.LocalDate;
3334
import org.joda.time.LocalDateTime;
3435
import scala.Option;
3536
import scala.concurrent.ExecutionContext;
3637
import scala.runtime.AbstractFunction1;
3738

38-
import java.util.ArrayList;
39-
import java.util.Collections;
40-
import java.util.List;
41-
import java.util.UUID;
39+
import java.time.Instant;
40+
import java.util.*;
4241

4342
/**
4443
* Implementation of {@link SQLConnection} using the {@link AsyncConnectionPool}.
@@ -323,7 +322,7 @@ public Void apply(Object value) {
323322
} else if (value instanceof LocalDate) {
324323
array.add(value.toString());
325324
} else if (value instanceof DateTime) {
326-
array.add(value.toString());
325+
array.add(Instant.ofEpochMilli(((DateTime) value).getMillis()));
327326
} else if (value instanceof UUID) {
328327
array.add(value.toString());
329328
} else {

src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public void testInsertedIds(TestContext context) {
9494
});
9595
}
9696

97+
@Override
98+
protected void compareInstantStrings(TestContext context, String result, String expected) {
99+
context.assertEquals(result, expected.replaceFirst("\\.\\d{3}$", ".000"));
100+
}
101+
97102
@Override
98103
protected String createByteArray1TableColumn() {
99104
return "BIT(1)";

src/test/java/io/vertx/ext/asyncsql/SQLTestBase.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.Test;
3030

3131
import java.math.BigDecimal;
32+
import java.time.Instant;
3233
import java.util.Arrays;
3334
import java.util.List;
3435

@@ -602,6 +603,40 @@ public void testInvalidInsertStatement(TestContext context) {
602603
});
603604
}
604605

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+
605640
protected void setSqlModeIfPossible(Handler<Void> handler) {
606641
handler.handle(null);
607642
}

0 commit comments

Comments
 (0)