Skip to content

Commit

Permalink
Merge pull request #54 from vert-x3/issues/issue-53
Browse files Browse the repository at this point in the history
Fixes #53: TS WITHOUT TZ are returned as String, TS WITH TZ are conve…
  • Loading branch information
Narigo committed Aug 4, 2016
2 parents 18e90d4 + 09e8153 commit f37e773
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/main/asciidoc/groovy/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ application.

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

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

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

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

=== In an application using a vert.x distributions
Expand Down
6 changes: 3 additions & 3 deletions src/main/asciidoc/java/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ application.

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

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

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

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

=== In an application using a vert.x distributions
Expand Down
6 changes: 3 additions & 3 deletions src/main/asciidoc/js/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ application.

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

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

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

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

=== In an application using a vert.x distributions
Expand Down
6 changes: 3 additions & 3 deletions src/main/asciidoc/ruby/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ application.

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

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

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

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

=== In an application using a vert.x distributions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@
import io.vertx.ext.sql.TransactionIsolation;
import io.vertx.ext.sql.UpdateResult;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import scala.Option;
import scala.concurrent.ExecutionContext;
import scala.runtime.AbstractFunction1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.time.Instant;
import java.util.*;

/**
* Implementation of {@link SQLConnection} using the {@link AsyncConnectionPool}.
Expand Down Expand Up @@ -323,7 +322,7 @@ public Void apply(Object value) {
} else if (value instanceof LocalDate) {
array.add(value.toString());
} else if (value instanceof DateTime) {
array.add(value.toString());
array.add(Instant.ofEpochMilli(((DateTime) value).getMillis()));
} else if (value instanceof UUID) {
array.add(value.toString());
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/io/vertx/ext/asyncsql/MySQLClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public void testInsertedIds(TestContext context) {
});
}

@Override
protected void compareInstantStrings(TestContext context, String result, String expected) {
context.assertEquals(result, expected.replaceFirst("\\.\\d{3}$", ".000"));
}

@Override
protected String createByteArray1TableColumn() {
return "BIT(1)";
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/io/vertx/ext/asyncsql/SQLTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.junit.Test;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -602,6 +603,40 @@ public void testInvalidInsertStatement(TestContext context) {
});
}

@Test
public void testInstant(TestContext context) {
Async async = context.async();
client.getConnection(ar -> {
ensureSuccess(context, ar);
conn = ar.result();
conn.execute("DROP TABLE IF EXISTS test_table", ar1 -> {
ensureSuccess(context, ar1);
conn.execute("CREATE TABLE test_table (instant TIMESTAMP)", ar2 -> {
ensureSuccess(context, ar2);
Instant now = Instant.now();
conn.queryWithParams("INSERT INTO test_table (instant) VALUES (?)", new JsonArray().add(now), ar3 -> {
ensureSuccess(context, ar3);
conn.query("SELECT instant FROM test_table", ar4 -> {
ensureSuccess(context, ar4);
// timestamps with out time zone are returned as strings, so we must compare to the original instant
// ignoring the timezone offset (meaning ignore everything after char 23)
compareInstantStrings(
context,
ar4.result().getResults().get(0).getString(0),
now.toString().substring(0, 23)
);
async.complete();
});
});
});
});
});
}

protected void compareInstantStrings(TestContext context, String result, String expected) {
context.assertEquals(result, expected);
}

protected void setSqlModeIfPossible(Handler<Void> handler) {
handler.handle(null);
}
Expand Down

0 comments on commit f37e773

Please sign in to comment.