|
|
|
@ -25,7 +25,6 @@ import java.io.Reader;
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.sql.ResultSetMetaData;
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
@ -36,9 +35,9 @@ import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
@ -64,22 +63,15 @@ public abstract class CommonTest {
|
|
|
|
|
|
|
|
|
|
protected Database db;
|
|
|
|
|
|
|
|
|
|
protected LocalDateTime now = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS);
|
|
|
|
|
protected LocalDateTime now;
|
|
|
|
|
|
|
|
|
|
protected LocalDate localDateNow = LocalDate.now();
|
|
|
|
|
protected LocalDate localDateNow;
|
|
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
|
public void setupJdbc() throws Exception {
|
|
|
|
|
now = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS);
|
|
|
|
|
localDateNow = LocalDate.now();
|
|
|
|
|
dbp = createDatabaseProvider(new OptionsOverride() {
|
|
|
|
|
@Override
|
|
|
|
|
public LocalDateTime currentDate() {
|
|
|
|
|
return now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Calendar calendarForTimestamps() {
|
|
|
|
|
return Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
db = dbp.get();
|
|
|
|
|
db.dropTableQuietly(TEST_TABLE_NAME);
|
|
|
|
@ -153,13 +145,13 @@ public abstract class CommonTest {
|
|
|
|
|
.addColumn("str_fixed").asStringFixed(1).table()
|
|
|
|
|
.addColumn("str_lob").asClob().table()
|
|
|
|
|
.addColumn("bin_blob").asBlob().table()
|
|
|
|
|
.addColumn("date_millis").asDate().table()
|
|
|
|
|
.addColumn("date_millis").asLocalDateTime().table()
|
|
|
|
|
.addColumn("local_date").asLocalDate().table().schema().execute(db);
|
|
|
|
|
|
|
|
|
|
BigDecimal bigDecimal = new BigDecimal("5.3");
|
|
|
|
|
db.toInsert("insert into dbtest values (?,?,?,?,?,?,?,?,?,?,?)").argInteger(1).argLong(2L).argFloat(3.2f).argDouble(4.2)
|
|
|
|
|
.argBigDecimal(bigDecimal).argString("Hello").argString("T").argClobString("World")
|
|
|
|
|
.argBlobBytes("More".getBytes()).argDate(now).argLocalDate(localDateNow).insert(1);
|
|
|
|
|
.argBlobBytes("More".getBytes()).argLocalDateTime(now).argLocalDate(localDateNow).insert(1);
|
|
|
|
|
|
|
|
|
|
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
|
|
|
|
+ "bin_blob, date_millis, local_date from dbtest")
|
|
|
|
@ -286,14 +278,14 @@ public abstract class CommonTest {
|
|
|
|
|
.argBigDecimal("bd", bigDecimal)
|
|
|
|
|
.argString("s", "Hello")
|
|
|
|
|
.argString("sf", "T")
|
|
|
|
|
.argDate("date", now)
|
|
|
|
|
.argLocalDateTime("date", now)
|
|
|
|
|
.argLocalDate("local_date", localDateNow)
|
|
|
|
|
.queryLongOrNull());
|
|
|
|
|
List<Long> result = db.toSelect("select count(*) from dbtest where nbr_integer=:i and nbr_long=:l and "
|
|
|
|
|
+ "abs(nbr_float-:f)<0.01 and abs(nbr_double-:d)<0.01 and nbr_big_decimal=:bd and str_varchar=:s "
|
|
|
|
|
+ "and str_fixed=:sf and date_millis=:date and local_date=:local_date").argInteger("i", 1).argLong("l", 2L).argFloat("f", 3.2f)
|
|
|
|
|
.argDouble("d", 4.2).argBigDecimal("bd", bigDecimal).argString("s", "Hello").argString("sf", "T")
|
|
|
|
|
.argDate("date", now).argLocalDate("local_date", localDateNow).queryLongs();
|
|
|
|
|
.argLocalDateTime("date", now).argLocalDate("local_date", localDateNow).queryLongs();
|
|
|
|
|
assertEquals(1, result.size());
|
|
|
|
|
assertEquals(Long.valueOf(1), result.get(0));
|
|
|
|
|
}
|
|
|
|
@ -312,7 +304,7 @@ public abstract class CommonTest {
|
|
|
|
|
.addColumn("str_fixed").asStringFixed(1).table()
|
|
|
|
|
.addColumn("str_lob").asClob().table()
|
|
|
|
|
.addColumn("bin_blob").asBlob().table()
|
|
|
|
|
.addColumn("date_millis").asDate().table()
|
|
|
|
|
.addColumn("date_millis").asLocalDateTime().table()
|
|
|
|
|
.addColumn("local_date").asLocalDate().table().schema().execute(db);
|
|
|
|
|
|
|
|
|
|
BigDecimal bigDecimal = new BigDecimal("5.3");
|
|
|
|
@ -327,12 +319,12 @@ public abstract class CommonTest {
|
|
|
|
|
.argString("T")
|
|
|
|
|
.argClobString("World")
|
|
|
|
|
.argBlobBytes("More".getBytes())
|
|
|
|
|
.argDate(now)
|
|
|
|
|
.argLocalDateTime(now)
|
|
|
|
|
.argLocalDate(localDateNow).insert());
|
|
|
|
|
db.toUpdate("update dbtest set nbr_integer=?, nbr_long=?, nbr_float=?, nbr_double=?, nbr_big_decimal=?, "
|
|
|
|
|
+ "str_varchar=?, str_fixed=?, str_lob=?, bin_blob=?, date_millis=?, local_date=?").argInteger(null).argLong(null)
|
|
|
|
|
.argFloat(null).argDouble(null).argBigDecimal(null).argString(null).argString(null).argClobString(null)
|
|
|
|
|
.argBlobBytes(null).argDate(null).argLocalDate(null).update(1);
|
|
|
|
|
.argBlobBytes(null).argLocalDateTime(null).argLocalDate(null).update(1);
|
|
|
|
|
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
|
|
|
|
+ "bin_blob, date_millis, local_date from dbtest").query((RowsHandler<Void>) rs -> {
|
|
|
|
|
assertTrue(rs.next());
|
|
|
|
@ -363,7 +355,7 @@ public abstract class CommonTest {
|
|
|
|
|
assertEquals(1, db.toUpdate("update dbtest set nbr_integer=?, nbr_long=?, nbr_float=?, nbr_double=?, "
|
|
|
|
|
+ "nbr_big_decimal=?, str_varchar=?, str_fixed=?, str_lob=?, bin_blob=?, date_millis=?, local_date=?").argInteger(1)
|
|
|
|
|
.argLong(2L).argFloat(3.2f).argDouble(4.2).argBigDecimal(bigDecimal).argString("Hello").argString("T")
|
|
|
|
|
.argClobString("World").argBlobBytes("More".getBytes()).argDate(now).argLocalDate(localDateNow).update());
|
|
|
|
|
.argClobString("World").argBlobBytes("More".getBytes()).argLocalDateTime(now).argLocalDate(localDateNow).update());
|
|
|
|
|
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
|
|
|
|
+ "bin_blob, date_millis, local_date from dbtest").query((RowsHandler<Void>) rs -> {
|
|
|
|
|
assertTrue(rs.next());
|
|
|
|
@ -426,20 +418,20 @@ public abstract class CommonTest {
|
|
|
|
|
.addColumn("str_fixed").asStringFixed(1).table()
|
|
|
|
|
.addColumn("str_lob").asClob().table()
|
|
|
|
|
.addColumn("bin_blob").asBlob().table()
|
|
|
|
|
.addColumn("date_millis").asDate().table()
|
|
|
|
|
.addColumn("date_millis").asLocalDateTime().table()
|
|
|
|
|
.addColumn("local_date").asLocalDate().table().schema().execute(db);
|
|
|
|
|
BigDecimal bigDecimal = new BigDecimal("5.3");
|
|
|
|
|
db.toInsert("insert into dbtest values (:pk,:a,:b,:c,:d,:e,:f,:sf,:g,:h,:i,:j)").argLong(":pk", 1L).argInteger(":a", 1)
|
|
|
|
|
.argLong(":b", 2L).argFloat(":c", 3.2f).argDouble(":d", 4.2).argBigDecimal(":e", bigDecimal)
|
|
|
|
|
.argString(":f", "Hello").argString(":sf", "T")
|
|
|
|
|
.argClobString(":g", "World").argBlobBytes(":h", "More".getBytes())
|
|
|
|
|
.argDate(":i", now).argLocalDate(":j", localDateNow).insert(1);
|
|
|
|
|
.argLocalDateTime(":i", now).argLocalDate(":j", localDateNow).insert(1);
|
|
|
|
|
db.toUpdate("update dbtest set nbr_integer=:a, nbr_long=:b, nbr_float=:c, nbr_double=:d, nbr_big_decimal=:e, "
|
|
|
|
|
+ "str_varchar=:f, str_fixed=:sf, str_lob=:g, bin_blob=:h, date_millis=:i, local_date=:j").argInteger(":a", null)
|
|
|
|
|
.argLong(":b", null).argFloat(":c", null).argDouble(":d", null).argBigDecimal(":e", null)
|
|
|
|
|
.argString(":f", null).argString(":sf", null)
|
|
|
|
|
.argClobString(":g", null).argBlobBytes(":h", null)
|
|
|
|
|
.argDate(":i", null).argLocalDate(":j", null).update(1);
|
|
|
|
|
.argLocalDateTime(":i", null).argLocalDate(":j", null).update(1);
|
|
|
|
|
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
|
|
|
|
+ "bin_blob, date_millis, local_date from dbtest").query((RowsHandler<Void>) rs -> {
|
|
|
|
|
assertTrue(rs.next());
|
|
|
|
@ -472,7 +464,7 @@ public abstract class CommonTest {
|
|
|
|
|
.argLong(":b", 2L).argFloat(":c", 3.2f).argDouble(":d", 4.2).argBigDecimal(":e", bigDecimal)
|
|
|
|
|
.argString(":f", "Hello").argString(":sf", "T")
|
|
|
|
|
.argClobString(":g", "World").argBlobBytes(":h", "More".getBytes())
|
|
|
|
|
.argDate(":i", now).argLocalDate(":j", localDateNow).update(1);
|
|
|
|
|
.argLocalDateTime(":i", now).argLocalDate(":j", localDateNow).update(1);
|
|
|
|
|
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
|
|
|
|
+ "bin_blob, date_millis, local_date from dbtest")
|
|
|
|
|
.query((RowsHandler<Void>) rs -> {
|
|
|
|
@ -537,11 +529,11 @@ public abstract class CommonTest {
|
|
|
|
|
.addColumn("str_fixed").asStringFixed(1).table()
|
|
|
|
|
.addColumn("str_lob").asClob().table()
|
|
|
|
|
.addColumn("bin_blob").asBlob().table()
|
|
|
|
|
.addColumn("date_millis").asDate().table()
|
|
|
|
|
.addColumn("date_millis").asLocalDateTime().table()
|
|
|
|
|
.addColumn("local_date").asLocalDate().table().schema().execute(db);
|
|
|
|
|
db.toInsert("insert into dbtest values (?,?,?,?,?,?,?,?,?,?,?,?)").argLong(1L).argInteger(null).argLong(null)
|
|
|
|
|
.argFloat(null).argDouble(null).argBigDecimal(null).argString(null).argString(null).argClobString(null)
|
|
|
|
|
.argBlobBytes(null).argDate(null).argLocalDate(null).insert(1);
|
|
|
|
|
.argBlobBytes(null).argLocalDateTime(null).argLocalDate(null).insert(1);
|
|
|
|
|
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
|
|
|
|
+ "bin_blob, date_millis, local_date from dbtest")
|
|
|
|
|
.query((RowsHandler<Void>) rs -> {
|
|
|
|
@ -604,7 +596,7 @@ public abstract class CommonTest {
|
|
|
|
|
String dateColumnName = "local_date";
|
|
|
|
|
new Schema()
|
|
|
|
|
.addTable("dbtest")
|
|
|
|
|
.addColumn(timestampColumnName).asDate().table()
|
|
|
|
|
.addColumn(timestampColumnName).asLocalDateTime().table()
|
|
|
|
|
.addColumn(dateColumnName).asLocalDate().table().schema().execute(db);
|
|
|
|
|
db.toSelect("select * from dbtest").query((RowsHandler<Void>) rs -> {
|
|
|
|
|
ResultSetMetaData metadata = rs.getMetadata();
|
|
|
|
@ -612,8 +604,10 @@ public abstract class CommonTest {
|
|
|
|
|
String columnName = metadata.getColumnName(i);
|
|
|
|
|
String columnType = metadata.getColumnTypeName(i);
|
|
|
|
|
if (columnName.equalsIgnoreCase(timestampColumnName)) {
|
|
|
|
|
if ("sqlserver".equals(db.flavor().toString())) {
|
|
|
|
|
if ("sqlserver".equals(db.flavor().getName())) {
|
|
|
|
|
assertEquals("DATETIME2", columnType.toUpperCase());
|
|
|
|
|
} else if ("hsqldb".equals(db.flavor().getName())) {
|
|
|
|
|
assertEquals("TIMESTAMP WITH TIME ZONE", columnType.toUpperCase());
|
|
|
|
|
} else {
|
|
|
|
|
assertEquals("TIMESTAMP", columnType.toUpperCase());
|
|
|
|
|
}
|
|
|
|
@ -629,11 +623,11 @@ public abstract class CommonTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void intervals() {
|
|
|
|
|
new Schema().addTable("dbtest").addColumn("d").asDate().schema().execute(db);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)").argDate(now).insert(1);
|
|
|
|
|
new Schema().addTable("dbtest").addColumn("d").asLocalDateTime().schema().execute(db);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)").argLocalDateTime(now).insert(1);
|
|
|
|
|
assertEquals(1, db.toSelect("select count(1) from dbtest where d - interval '1' hour * ? < ?")
|
|
|
|
|
.argInteger(2)
|
|
|
|
|
.argDate(now)
|
|
|
|
|
.argLocalDateTime(now)
|
|
|
|
|
.queryIntegerOrZero());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -650,7 +644,7 @@ public abstract class CommonTest {
|
|
|
|
|
.addColumn("str_lob").asClob().table()
|
|
|
|
|
.addColumn("bin_blob").asBlob().table()
|
|
|
|
|
.addColumn("boolean_flag").asBoolean().table()
|
|
|
|
|
.addColumn("date_millis").asDate().table()
|
|
|
|
|
.addColumn("date_millis").asLocalDateTime().table()
|
|
|
|
|
.addColumn("local_date").asLocalDate().schema().execute(db);
|
|
|
|
|
db.toInsert("insert into dbtest (nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar,"
|
|
|
|
|
+ " str_fixed, str_lob, bin_blob, boolean_flag, date_millis, local_date) values (?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
|
|
@ -658,14 +652,16 @@ public abstract class CommonTest {
|
|
|
|
|
.argDouble(Double.MAX_VALUE).argBigDecimal(new BigDecimal("123.456"))
|
|
|
|
|
.argString("hello").argString("Z").argClobString("hello again")
|
|
|
|
|
.argBlobBytes(new byte[]{'1', '2'}).argBoolean(true)
|
|
|
|
|
.argDateNowPerApp().argLocalDate(localDateNow).insert(1);
|
|
|
|
|
.argLocalDateTime(now)
|
|
|
|
|
.argLocalDate(localDateNow).insert(1);
|
|
|
|
|
db.toInsert("insert into dbtest (nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar,"
|
|
|
|
|
+ " str_fixed, str_lob, bin_blob, boolean_flag, date_millis, local_date) values (?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
|
|
|
.argInteger(Integer.MIN_VALUE).argLong(Long.MIN_VALUE).argFloat(0.000001f)
|
|
|
|
|
.argDouble(Double.MIN_VALUE).argBigDecimal(new BigDecimal("-123.456"))
|
|
|
|
|
.argString("goodbye").argString("A").argClobString("bye again")
|
|
|
|
|
.argBlobBytes(new byte[]{'3', '4'}).argBoolean(false)
|
|
|
|
|
.argDateNowPerApp().argLocalDate(localDateNow).insert(1);
|
|
|
|
|
.argLocalDateTime(now)
|
|
|
|
|
.argLocalDate(localDateNow).insert(1);
|
|
|
|
|
String expectedSchema = new Schema().addTable("dbtest2")
|
|
|
|
|
.addColumn("nbr_integer").asInteger().table()
|
|
|
|
|
.addColumn("nbr_long").asLong().table()
|
|
|
|
@ -677,7 +673,7 @@ public abstract class CommonTest {
|
|
|
|
|
.addColumn("str_lob").asClob().table()
|
|
|
|
|
.addColumn("bin_blob").asBlob().table()
|
|
|
|
|
.addColumn("boolean_flag").asBoolean().table()
|
|
|
|
|
.addColumn("date_millis").asDate().table()
|
|
|
|
|
.addColumn("date_millis").asLocalDateTime().table()
|
|
|
|
|
.addColumn("local_date").asLocalDate().schema().print(db.flavor());
|
|
|
|
|
List<SqlArgs> args = db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal,"
|
|
|
|
|
+ " str_varchar, str_fixed, str_lob, bin_blob, boolean_flag, date_millis, local_date from dbtest")
|
|
|
|
@ -719,7 +715,7 @@ public abstract class CommonTest {
|
|
|
|
|
.argClobString("str_lob", "bye again")
|
|
|
|
|
.argBlobBytes("bin_blob", new byte[]{'3', '4'})
|
|
|
|
|
.argString("boolean_flag", "N")//.argBoolean("boolean_flag", false)
|
|
|
|
|
.argDate("date_millis", now)
|
|
|
|
|
.argLocalDateTime("date_millis", now)
|
|
|
|
|
.argLocalDate("local_date", localDateNow),
|
|
|
|
|
new SqlArgs().argInteger("nbr_integer", Integer.MAX_VALUE)
|
|
|
|
|
.argLong("nbr_long", Long.MAX_VALUE)
|
|
|
|
@ -731,7 +727,7 @@ public abstract class CommonTest {
|
|
|
|
|
.argClobString("str_lob", "hello again")
|
|
|
|
|
.argBlobBytes("bin_blob", new byte[]{'1', '2'})
|
|
|
|
|
.argString("boolean_flag", "Y")//.argBoolean("boolean_flag", true)
|
|
|
|
|
.argDate("date_millis", now)
|
|
|
|
|
.argLocalDateTime("date_millis", now)
|
|
|
|
|
.argLocalDate("local_date", localDateNow)),
|
|
|
|
|
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal,"
|
|
|
|
|
+ " str_varchar, str_fixed, str_lob, bin_blob, boolean_flag, date_millis, local_date from dbtest2 order by 1")
|
|
|
|
@ -1368,25 +1364,26 @@ public abstract class CommonTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void insertReturningAppDate() {
|
|
|
|
|
db.dropSequenceQuietly("dbtest_seq");
|
|
|
|
|
|
|
|
|
|
new Schema()
|
|
|
|
|
.addTable("dbtest")
|
|
|
|
|
.addColumn("pk").primaryKey().table()
|
|
|
|
|
.addColumn("d").asDate().table().schema()
|
|
|
|
|
.addColumn("d")
|
|
|
|
|
.asLocalDateTime()
|
|
|
|
|
.table()
|
|
|
|
|
.schema()
|
|
|
|
|
.addSequence("dbtest_seq").schema()
|
|
|
|
|
.execute(db);
|
|
|
|
|
|
|
|
|
|
db.toInsert("insert into dbtest (pk, d) values (:seq, :d)")
|
|
|
|
|
.argPkSeq(":seq", "dbtest_seq")
|
|
|
|
|
.argDateNowPerApp(":d")
|
|
|
|
|
.argLocalDateTime(":d", now)
|
|
|
|
|
.insertReturning("dbtest", "pk", rs -> {
|
|
|
|
|
assertTrue(rs.next());
|
|
|
|
|
assertEquals(Long.valueOf(1L), rs.getLongOrNull(1));
|
|
|
|
|
assertThat(rs.getLocalDateTimeOrNull(2), equalTo(now));
|
|
|
|
|
assertThat(rs.getLocalDateTimeOrNull(2, ZoneId.systemDefault()), equalTo(now));
|
|
|
|
|
assertFalse(rs.next());
|
|
|
|
|
return null;
|
|
|
|
|
}, "d");
|
|
|
|
|
assertEquals(Long.valueOf(1L), db.toSelect("select count(*) from dbtest where d=?").argDate(now).queryLongOrNull());
|
|
|
|
|
assertEquals(Long.valueOf(1L), db.toSelect("select count(*) from dbtest where d=?").argLocalDateTime(now).queryLongOrNull());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -1394,18 +1391,20 @@ public abstract class CommonTest {
|
|
|
|
|
new Schema()
|
|
|
|
|
.addTable("dbtest")
|
|
|
|
|
.addColumn("pk").primaryKey().table()
|
|
|
|
|
.addColumn("d").asDate().table()
|
|
|
|
|
.addColumn("d2").asDate().table()
|
|
|
|
|
.addColumn("d").asLocalDateTime().table()
|
|
|
|
|
.addColumn("d2").asLocalDateTime().table()
|
|
|
|
|
.addColumn("d3").asLocalDate().table()
|
|
|
|
|
.addColumn("d4").asLocalDate().table()
|
|
|
|
|
.addColumn("s").asString(5).table()
|
|
|
|
|
.addColumn("s2").asString(5).table()
|
|
|
|
|
.addColumn("i").asInteger().table().schema()
|
|
|
|
|
.execute(db);
|
|
|
|
|
|
|
|
|
|
db.toInsert("insert into dbtest (pk, d, d3, s) values (?,?,?,?)")
|
|
|
|
|
.argLong(1L).argDateNowPerApp().argLocalDate(localDateNow).argString("foo").insert(1);
|
|
|
|
|
|
|
|
|
|
.argLong(1L)
|
|
|
|
|
.argLocalDateTime(now)
|
|
|
|
|
.argLocalDate(localDateNow)
|
|
|
|
|
.argString("foo")
|
|
|
|
|
.insert(1);
|
|
|
|
|
assertEquals(Long.valueOf(1L), db.toSelect("select pk from dbtest").queryLongOrNull());
|
|
|
|
|
assertNull(db.toSelect("select pk from dbtest where 1=0").queryLongOrNull());
|
|
|
|
|
assertNull(db.toSelect("select i from dbtest").queryLongOrNull());
|
|
|
|
@ -1415,7 +1414,6 @@ public abstract class CommonTest {
|
|
|
|
|
assertEquals(1L, (long) db.toSelect("select pk from dbtest").queryLongs().get(0));
|
|
|
|
|
assertTrue(db.toSelect("select pk from dbtest where 1=0").queryLongs().isEmpty());
|
|
|
|
|
assertTrue(db.toSelect("select i from dbtest").queryLongs().isEmpty());
|
|
|
|
|
|
|
|
|
|
assertEquals(Integer.valueOf(1), db.toSelect("select pk from dbtest").queryIntegerOrNull());
|
|
|
|
|
assertNull(db.toSelect("select pk from dbtest where 1=0").queryIntegerOrNull());
|
|
|
|
|
assertNull(db.toSelect("select i from dbtest").queryIntegerOrNull());
|
|
|
|
@ -1425,7 +1423,6 @@ public abstract class CommonTest {
|
|
|
|
|
assertEquals(1L, (int) db.toSelect("select pk from dbtest").queryIntegers().get(0));
|
|
|
|
|
assertTrue(db.toSelect("select pk from dbtest where 1=0").queryIntegers().isEmpty());
|
|
|
|
|
assertTrue(db.toSelect("select i from dbtest").queryIntegers().isEmpty());
|
|
|
|
|
|
|
|
|
|
assertEquals("foo", db.toSelect("select s from dbtest").queryStringOrNull());
|
|
|
|
|
assertNull(db.toSelect("select s from dbtest where 1=0").queryStringOrNull());
|
|
|
|
|
assertNull(db.toSelect("select s2 from dbtest").queryStringOrNull());
|
|
|
|
@ -1435,13 +1432,12 @@ public abstract class CommonTest {
|
|
|
|
|
assertEquals("foo", db.toSelect("select s from dbtest").queryStrings().get(0));
|
|
|
|
|
assertTrue(db.toSelect("select s from dbtest where 1=0").queryStrings().isEmpty());
|
|
|
|
|
assertTrue(db.toSelect("select s2 from dbtest").queryStrings().isEmpty());
|
|
|
|
|
|
|
|
|
|
assertEquals(now, db.toSelect("select d from dbtest").queryDateOrNull());
|
|
|
|
|
assertNull(db.toSelect("select d from dbtest where 1=0").queryDateOrNull());
|
|
|
|
|
assertNull(db.toSelect("select d2 from dbtest").queryDateOrNull());
|
|
|
|
|
assertEquals(db.toSelect("select d from dbtest").queryDates().get(0), now);
|
|
|
|
|
assertTrue(db.toSelect("select d from dbtest where 1=0").queryDates().isEmpty());
|
|
|
|
|
assertTrue(db.toSelect("select d2 from dbtest").queryDates().isEmpty());
|
|
|
|
|
assertEquals(now, db.toSelect("select d from dbtest").queryLocalDateTimeOrNull());
|
|
|
|
|
assertNull(db.toSelect("select d from dbtest where 1=0").queryLocalDateTimeOrNull());
|
|
|
|
|
assertNull(db.toSelect("select d2 from dbtest").queryLocalDateTimeOrNull());
|
|
|
|
|
assertEquals(db.toSelect("select d from dbtest").queryLocalDateTimes().get(0), now);
|
|
|
|
|
assertTrue(db.toSelect("select d from dbtest where 1=0").queryLocalDateTimes().isEmpty());
|
|
|
|
|
assertTrue(db.toSelect("select d2 from dbtest").queryLocalDateTimes().isEmpty());
|
|
|
|
|
|
|
|
|
|
assertEquals(localDateNow, db.toSelect("select d3 from dbtest").queryLocalDateOrNull());
|
|
|
|
|
assertNull(db.toSelect("select d3 from dbtest where 1=0").queryLocalDateOrNull());
|
|
|
|
@ -1511,12 +1507,12 @@ public abstract class CommonTest {
|
|
|
|
|
new Schema()
|
|
|
|
|
.addTable("dbtest")
|
|
|
|
|
.addColumn("pk").primaryKey().table()
|
|
|
|
|
.addColumn("d").asDate().table().schema()
|
|
|
|
|
.addColumn("d").asLocalDateTime().table().schema()
|
|
|
|
|
.addSequence("dbtest_seq").schema()
|
|
|
|
|
.execute(db);
|
|
|
|
|
LocalDateTime dbNow = db.toInsert("insert into dbtest (pk, d) values (:seq, :d)")
|
|
|
|
|
.argPkSeq(":seq", "dbtest_seq")
|
|
|
|
|
.argDateNowPerDb(":d")
|
|
|
|
|
.argLocalDateTimeNowPerDb(":d")
|
|
|
|
|
.insertReturning("dbtest", "pk", rs -> {
|
|
|
|
|
assertTrue(rs.next());
|
|
|
|
|
assertEquals(Long.valueOf(1L), rs.getLongOrNull(1));
|
|
|
|
@ -1524,7 +1520,8 @@ public abstract class CommonTest {
|
|
|
|
|
assertFalse(rs.next());
|
|
|
|
|
return dbDate;
|
|
|
|
|
}, "d");
|
|
|
|
|
assertEquals(Long.valueOf(1L), db.toSelect("select count(*) from dbtest where d=?").argDate(dbNow).queryLongOrNull());
|
|
|
|
|
assertEquals(Long.valueOf(1L),
|
|
|
|
|
db.toSelect("select count(*) from dbtest where d = ?").argLocalDateTime(dbNow).queryLongOrNull());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -1581,12 +1578,12 @@ public abstract class CommonTest {
|
|
|
|
|
for (int attempts = 1; attempts <= 10; attempts++) {
|
|
|
|
|
new Schema()
|
|
|
|
|
.addTable("dbtest")
|
|
|
|
|
.addColumn("d").asDate().table().schema()
|
|
|
|
|
.addColumn("d").asLocalDateTime().table().schema()
|
|
|
|
|
.execute(db);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)")
|
|
|
|
|
.argDateNowPerDb()
|
|
|
|
|
.argLocalDateTimeNowPerDb()
|
|
|
|
|
.insert(1);
|
|
|
|
|
LocalDateTime dbNow = db.toSelect("select d from dbtest").queryDateOrNull();
|
|
|
|
|
LocalDateTime dbNow = db.toSelect("select d from dbtest").queryLocalDateTimeOrNull();
|
|
|
|
|
if (dbNow != null && dbNow.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() % 10 != 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -1600,19 +1597,17 @@ public abstract class CommonTest {
|
|
|
|
|
public void dateRoundTrip() {
|
|
|
|
|
new Schema()
|
|
|
|
|
.addTable("dbtest")
|
|
|
|
|
.addColumn("d1").asDate().table()
|
|
|
|
|
.addColumn("d2").asDate().table().schema()
|
|
|
|
|
.addColumn("d1").asLocalDateTime().table()
|
|
|
|
|
.addColumn("d2").asLocalDateTime().table()
|
|
|
|
|
.schema()
|
|
|
|
|
.execute(db);
|
|
|
|
|
// Store current time as per the database
|
|
|
|
|
db.toInsert("insert into dbtest (d1) values (?)")
|
|
|
|
|
.argDateNowPerDb()
|
|
|
|
|
.argLocalDateTimeNowPerDb()
|
|
|
|
|
.insert(1);
|
|
|
|
|
// Now pull it out, put it back in, and verify it matches in the database
|
|
|
|
|
LocalDateTime dbNow = db.toSelect("select d1 from dbtest").queryDateOrNull();
|
|
|
|
|
db.toUpdate("update dbtest set d2=?")
|
|
|
|
|
.argDate(dbNow)
|
|
|
|
|
LocalDateTime dbNow = db.toSelect("select d1 from dbtest").queryLocalDateTimeOrNull();
|
|
|
|
|
db.toUpdate("update dbtest set d2 = ?")
|
|
|
|
|
.argLocalDateTime(dbNow)
|
|
|
|
|
.update(1);
|
|
|
|
|
|
|
|
|
|
assertEquals(Long.valueOf(1L), db.toSelect("select count(*) from dbtest where d1=d2").queryLongOrNull());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1620,66 +1615,75 @@ public abstract class CommonTest {
|
|
|
|
|
public void dateRoundTripTimezones() {
|
|
|
|
|
new Schema()
|
|
|
|
|
.addTable("dbtest")
|
|
|
|
|
.addColumn("d").asDate().table().schema()
|
|
|
|
|
.addColumn("d")
|
|
|
|
|
.asLocalDateTime()
|
|
|
|
|
.table()
|
|
|
|
|
.schema()
|
|
|
|
|
.execute(db);
|
|
|
|
|
Instant instant = Instant.ofEpochMilli(166656789L);
|
|
|
|
|
LocalDateTime dateMinus = LocalDateTime.ofInstant(instant, ZoneId.ofOffset("GMT", ZoneOffset.ofHours(-4)));
|
|
|
|
|
LocalDateTime datePlus = LocalDateTime.ofInstant(instant, ZoneId.ofOffset("GMT", ZoneOffset.ofHours(+4)));
|
|
|
|
|
TimeZone defaultTZ = TimeZone.getDefault();
|
|
|
|
|
try {
|
|
|
|
|
TimeZone.setDefault(TimeZone.getTimeZone("GMT-4:00"));
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)").argDate(dateMinus).insert(1);
|
|
|
|
|
LocalDateTime localDateTimeMinus = db.toSelect("select d from dbtest").queryDateOrNull();
|
|
|
|
|
assertEquals(dateMinus, localDateTimeMinus);
|
|
|
|
|
assertEquals("1970-01-02 18:17:36.789", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(localDateTimeMinus));
|
|
|
|
|
db.toDelete("delete from dbtest where d=?").argDate(dateMinus).update(1);
|
|
|
|
|
TimeZone.setDefault(TimeZone.getTimeZone("GMT+4:00"));
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)").argDate(datePlus).insert(1);
|
|
|
|
|
LocalDateTime localDateTimePlus = db.toSelect("select d from dbtest").queryDateOrNull();
|
|
|
|
|
assertEquals(datePlus, localDateTimePlus);
|
|
|
|
|
assertEquals("1970-01-03 02:17:36.789", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(localDateTimePlus));
|
|
|
|
|
db.toDelete("delete from dbtest where d=?").argDate(datePlus).update(1);
|
|
|
|
|
} finally {
|
|
|
|
|
TimeZone.setDefault(defaultTZ);
|
|
|
|
|
}
|
|
|
|
|
ZoneId dateMinusZone = ZoneId.ofOffset("GMT", ZoneOffset.ofHours(-4));
|
|
|
|
|
LocalDateTime dateMinus = LocalDateTime.ofInstant(instant, dateMinusZone);
|
|
|
|
|
ZoneId datePlusZone = ZoneId.ofOffset("GMT", ZoneOffset.ofHours(+4));
|
|
|
|
|
LocalDateTime datePlus = LocalDateTime.ofInstant(instant,datePlusZone);
|
|
|
|
|
logger.log(Level.INFO, "dateMinus = " + dateMinus);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)")
|
|
|
|
|
.argLocalDateTime(dateMinus)
|
|
|
|
|
.insert(1);
|
|
|
|
|
LocalDateTime localDateTimeMinus = db.toSelect("select d from dbtest")
|
|
|
|
|
.queryLocalDateTimeOrNull();
|
|
|
|
|
assertEquals(dateMinus, localDateTimeMinus);
|
|
|
|
|
assertEquals("1970-01-02 18:17:36.789",
|
|
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(localDateTimeMinus));
|
|
|
|
|
db.toDelete("delete from dbtest where d = ?").argLocalDateTime(dateMinus).update(1);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)")
|
|
|
|
|
.argLocalDateTime(datePlus)
|
|
|
|
|
.insert(1);
|
|
|
|
|
LocalDateTime localDateTimePlus = db.toSelect("select d from dbtest")
|
|
|
|
|
.queryLocalDateTimeOrNull(datePlusZone);
|
|
|
|
|
assertEquals(datePlus, localDateTimePlus);
|
|
|
|
|
assertEquals("1970-01-03 02:17:36.789",
|
|
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(localDateTimePlus));
|
|
|
|
|
db.toDelete("delete from dbtest where d = ?").argLocalDateTime(datePlus).update(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify the appropriate database flavor can correctly convert a {@code Date}
|
|
|
|
|
* Verify the appropriate database flavor can correctly convert a {@code LocalDateTime}
|
|
|
|
|
* into a SQL function representing a conversion from string to timestamp. This
|
|
|
|
|
* function is used to write debug SQL to the log in a way that could be manually
|
|
|
|
|
* executed if desired.
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void stringDateFunctions() {
|
|
|
|
|
public void stringLocalDateTimeFunctions() {
|
|
|
|
|
Instant instant = Instant.ofEpochMilli(166656789L);
|
|
|
|
|
LocalDateTime dateMinus = LocalDateTime.ofInstant(instant, ZoneId.ofOffset("GMT", ZoneOffset.ofHours(-4)));
|
|
|
|
|
LocalDateTime datePlus = LocalDateTime.ofInstant(instant, ZoneId.ofOffset("GMT", ZoneOffset.ofHours(+4)));
|
|
|
|
|
logger.info("LocalDateTime: " + dateMinus + " " + datePlus);
|
|
|
|
|
TimeZone defaultTZ = TimeZone.getDefault();
|
|
|
|
|
try {
|
|
|
|
|
TimeZone.setDefault(TimeZone.getTimeZone("GMT-4:00"));
|
|
|
|
|
new Schema().addTable("dbtest").addColumn("d").asDate().schema().execute(db);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values ("
|
|
|
|
|
+ db.flavor().dateAsSqlFunction(Timestamp.valueOf(dateMinus), db.options().calendarForTimestamps()).replace(":", "::") + ")")
|
|
|
|
|
.insert(1);
|
|
|
|
|
assertEquals("1970-01-02 18:17:36.789",
|
|
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(db.toSelect("select d from dbtest").queryDateOrNull()));
|
|
|
|
|
// Now do some client operations in a different time zone
|
|
|
|
|
TimeZone.setDefault(TimeZone.getTimeZone("GMT+4:00"));
|
|
|
|
|
// Verify regular arg maps date the same way even though our TimeZone is now different
|
|
|
|
|
db.toDelete("delete from dbtest where d=?").argDate(datePlus).update(1);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values ("
|
|
|
|
|
+ db.flavor().dateAsSqlFunction(Timestamp.valueOf(datePlus), db.options().calendarForTimestamps()).replace(":", "::") + ")")
|
|
|
|
|
.insert(1);
|
|
|
|
|
assertEquals("1970-01-03 02:17:36.789",
|
|
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(db.toSelect("select d from dbtest").queryDateOrNull()));
|
|
|
|
|
// Verify the function maps correctly for equals operations as well
|
|
|
|
|
db.toDelete("delete from dbtest where d=" + db.flavor().dateAsSqlFunction(Timestamp.valueOf(datePlus),
|
|
|
|
|
db.options().calendarForTimestamps()).replace(":", "::")).update(1);
|
|
|
|
|
} finally {
|
|
|
|
|
TimeZone.setDefault(defaultTZ);
|
|
|
|
|
}
|
|
|
|
|
ZoneId dateMinusZone = ZoneId.ofOffset("GMT", ZoneOffset.ofHours(-4));
|
|
|
|
|
LocalDateTime dateMinus = LocalDateTime.ofInstant(instant, dateMinusZone);
|
|
|
|
|
ZoneId datePlusZone = ZoneId.ofOffset("GMT", ZoneOffset.ofHours(+4));
|
|
|
|
|
LocalDateTime datePlus = LocalDateTime.ofInstant(instant, datePlusZone);
|
|
|
|
|
logger.info("LocalDateTime: dateMinus=" + dateMinus + " datePlus=" + datePlus);
|
|
|
|
|
new Schema().addTable("dbtest").addColumn("d")
|
|
|
|
|
.asLocalDateTime()
|
|
|
|
|
.schema()
|
|
|
|
|
.execute(db);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)")
|
|
|
|
|
.argLocalDateTime(dateMinus)
|
|
|
|
|
.insert(1);
|
|
|
|
|
LocalDateTime localDateTime = db.toSelect("select d from dbtest")
|
|
|
|
|
.queryLocalDateTimeOrNull();
|
|
|
|
|
assertEquals("1970-01-02 18:17:36.789",
|
|
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(localDateTime.atZone(dateMinusZone)));
|
|
|
|
|
db.toDelete("delete from dbtest where d = ?")
|
|
|
|
|
.argLocalDateTime(dateMinus)
|
|
|
|
|
.update(1);
|
|
|
|
|
db.toInsert("insert into dbtest (d) values (?)")
|
|
|
|
|
.argLocalDateTime(datePlus)
|
|
|
|
|
.insert(1);
|
|
|
|
|
localDateTime = db.toSelect("select d from dbtest")
|
|
|
|
|
.queryLocalDateTimeOrNull(datePlusZone);
|
|
|
|
|
assertEquals("1970-01-03 02:17:36.789",
|
|
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(localDateTime.atZone(datePlusZone)));
|
|
|
|
|
db.toDelete("delete from dbtest where d = ?")
|
|
|
|
|
.argLocalDateTime(datePlus)
|
|
|
|
|
.update(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -1687,12 +1691,12 @@ public abstract class CommonTest {
|
|
|
|
|
new Schema()
|
|
|
|
|
.addTable("dbtest")
|
|
|
|
|
.addColumn("pk").primaryKey().table()
|
|
|
|
|
.addColumn("d").asDate().table()
|
|
|
|
|
.addColumn("d").asLocalDateTime().table()
|
|
|
|
|
.addColumn("a").asInteger().table().schema()
|
|
|
|
|
.execute(db);
|
|
|
|
|
|
|
|
|
|
db.toSelect("select pk as \"time:: now??\" from dbtest where a=? and d=:now")
|
|
|
|
|
.argInteger(1).argDateNowPerDb("now").query(rs -> {
|
|
|
|
|
.argInteger(1).argLocalDateTimeNowPerDb("now").query(rs -> {
|
|
|
|
|
assertFalse(rs.next());
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|