Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.vertx.ext.sql.ResultSet;
import io.vertx.ext.sql.SQLConnection;
import io.vertx.ext.sql.UpdateResult;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import scala.Option;
Expand Down Expand Up @@ -282,6 +283,8 @@ public Void apply(Object value) {
array.add(value.toString());
} else if (value instanceof UUID) {
array.add(value.toString());
} else if (value instanceof DateTime) {
array.add(value.toString());
} else {
array.add(value);
}
Expand Down
49 changes: 49 additions & 0 deletions src/test/java/io/vertx/ext/asyncsql/PostgreSQLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,53 @@ public void someTest() throws Exception {
await();
}

@Test
public void queryTypeTimestampWithTimezoneTest() throws Exception {
asyncSqlClient.getConnection(onSuccess(conn -> {
conn.execute("CREATE TABLE IF NOT EXISTS timestamptest (ts timestamp with time zone)", onSuccess(resultSet -> {
conn.execute("INSERT INTO timestamptest (ts) VALUES (now())", onSuccess(rs1 -> {
conn.query("SELECT * FROM timestamptest;", onSuccess(rs2 -> {
assertNotNull(rs2);
assertNotNull(rs2.getResults());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add at least some check that the data received is a correctly formed date or something like that.

conn.execute("DROP TABLE timestamptest", onSuccess(rs3 -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I'd recommend dropping the table before the test and not after it. You can then check the database if anything strange happened after running the test.

conn.close((ar) -> {
if (ar.succeeded()) {
testComplete();
} else {
fail("should be able to close the asyncSqlClient");
}
});
}));
}));
}));
}));
}));

await();
}

@Test
public void queryTypeTimestampWithoutTimezoneTest() throws Exception {
asyncSqlClient.getConnection(onSuccess(conn -> {
conn.execute("CREATE TABLE IF NOT EXISTS timestamptest (ts timestamp without time zone)", onSuccess(resultSet -> {
conn.execute("INSERT INTO timestamptest (ts) VALUES (now())", onSuccess(rs1 -> {
conn.query("SELECT * FROM timestamptest;", onSuccess(rs2 -> {
assertNotNull(rs2);
assertNotNull(rs2.getResults());
conn.execute("DROP TABLE timestamptest", onSuccess(rs3 -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this test: Drop table before starting the test and assert that the received result is a correctly formed date.

conn.close((ar) -> {
if (ar.succeeded()) {
testComplete();
} else {
fail("should be able to close the asyncSqlClient");
}
});
}));
}));
}));
}));
}));

await();
}
}