提交 6423d69b authored 作者: andrei's avatar andrei

Merge branch 'master' of https://github.com/h2database/h2database into non_blocking

......@@ -6918,4 +6918,9 @@ public class Parser {
read();
return readTableOrView();
}
@Override
public String toString() {
return StringUtils.addAsterisk(sqlCommand, parseIndex);
}
}
......@@ -45,70 +45,70 @@ public class Constants {
*/
public static final String BUILD_VENDOR_AND_VERSION = null;
/**
* The TCP protocol version number 6.
*/
public static final int TCP_PROTOCOL_VERSION_6 = 6;
/**
* The TCP protocol version number 7.
*/
public static final int TCP_PROTOCOL_VERSION_7 = 7;
/**
* The TCP protocol version number 8.
* @since 1.2.143 (2010-09-18)
*/
public static final int TCP_PROTOCOL_VERSION_8 = 8;
/**
* The TCP protocol version number 9.
* @since 1.3.158 (2011-07-17)
*/
public static final int TCP_PROTOCOL_VERSION_9 = 9;
/**
* The TCP protocol version number 10.
* @since 1.3.162 (2011-11-26)
*/
public static final int TCP_PROTOCOL_VERSION_10 = 10;
/**
* The TCP protocol version number 11.
* @since 1.3.163 (2011-12-30)
*/
public static final int TCP_PROTOCOL_VERSION_11 = 11;
/**
* The TCP protocol version number 12.
* @since 1.3.168 (2012-07-13)
*/
public static final int TCP_PROTOCOL_VERSION_12 = 12;
/**
* The TCP protocol version number 13.
* @since 1.3.174 (2013-10-19)
*/
public static final int TCP_PROTOCOL_VERSION_13 = 13;
/**
* The TCP protocol version number 14.
* @since 1.3.176 (2014-04-05)
*/
public static final int TCP_PROTOCOL_VERSION_14 = 14;
/**
* The TCP protocol version number 15.
* @since 1.4.178 Beta (2014-05-02)
*/
public static final int TCP_PROTOCOL_VERSION_15 = 15;
/**
* The TCP protocol version number 16.
* @since 1.4.194 (2017-03-10)
*/
public static final int TCP_PROTOCOL_VERSION_16 = 16;
/**
* The TCP protocol version number 17.
* @since 1.4.197 (TODO)
*/
public static final int TCP_PROTOCOL_VERSION_17 = 17;
/**
* Minimum supported version of TCP protocol.
*/
public static final int TCP_PROTOCOL_VERSION_MIN_SUPPORTED = TCP_PROTOCOL_VERSION_6;
public static final int TCP_PROTOCOL_VERSION_MIN_SUPPORTED = TCP_PROTOCOL_VERSION_8;
/**
* Maximum supported version of TCP protocol.
......
......@@ -1221,12 +1221,10 @@ public class DateTimeUtils {
timeNanos -= correction;
if (timeNanos < 0) {
timeNanos += NANOS_PER_DAY;
dateValue = DateTimeUtils
.dateValueFromAbsoluteDay(absoluteDayFromDateValue(dateValue) - 1);
dateValue = decrementDateValue(dateValue);
} else if (timeNanos >= NANOS_PER_DAY) {
timeNanos -= NANOS_PER_DAY;
dateValue = DateTimeUtils
.dateValueFromAbsoluteDay(absoluteDayFromDateValue(dateValue) + 1);
dateValue = incrementDateValue(dateValue);
}
}
return ValueTimestampTimeZone.fromDateValueAndNanos(dateValue, timeNanos, (short) offsetMins);
......@@ -1320,6 +1318,63 @@ public class DateTimeUtils {
return dateValue(y, m + 3, (int) d);
}
/**
* Return the next date value.
*
* @param dateValue
* the date value
* @return the next date value
*/
public static long incrementDateValue(long dateValue) {
int year = yearFromDateValue(dateValue);
if (year == 1582) {
// Use slow way instead of rarely needed large custom code.
return dateValueFromAbsoluteDay(absoluteDayFromDateValue(dateValue) + 1);
}
int day = dayFromDateValue(dateValue);
if (day < 28) {
return dateValue + 1;
}
int month = monthFromDateValue(dateValue);
if (day < getDaysInMonth(year, month)) {
return dateValue + 1;
}
day = 1;
if (month < 12) {
month++;
} else {
month = 1;
year++;
}
return dateValue(year, month, day);
}
/**
* Return the previous date value.
*
* @param dateValue
* the date value
* @return the previous date value
*/
public static long decrementDateValue(long dateValue) {
int year = yearFromDateValue(dateValue);
if (year == 1582) {
// Use slow way instead of rarely needed large custom code.
return dateValueFromAbsoluteDay(absoluteDayFromDateValue(dateValue) - 1);
}
if (dayFromDateValue(dateValue) > 1) {
return dateValue - 1;
}
int month = monthFromDateValue(dateValue);
if (month > 1) {
month--;
} else {
month = 12;
year--;
}
return dateValue(year, month, getDaysInMonth(year, month));
}
/**
* Append a date to the string builder.
*
......
......@@ -349,19 +349,15 @@ public class Transfer {
case Value.TIME:
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
writeLong(((ValueTime) v).getNanos());
} else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
writeLong(DateTimeUtils.getTimeLocalWithoutDst(v.getTime()));
} else {
writeLong(v.getTime().getTime());
writeLong(DateTimeUtils.getTimeLocalWithoutDst(v.getTime()));
}
break;
case Value.DATE:
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
writeLong(((ValueDate) v).getDateValue());
} else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
writeLong(DateTimeUtils.getTimeLocalWithoutDst(v.getDate()));
} else {
writeLong(v.getDate().getTime());
writeLong(DateTimeUtils.getTimeLocalWithoutDst(v.getDate()));
}
break;
case Value.TIMESTAMP: {
......@@ -369,13 +365,9 @@ public class Transfer {
ValueTimestamp ts = (ValueTimestamp) v;
writeLong(ts.getDateValue());
writeLong(ts.getTimeNanos());
} else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
Timestamp ts = v.getTimestamp();
writeLong(DateTimeUtils.getTimeLocalWithoutDst(ts));
writeInt(ts.getNanos() % 1_000_000);
} else {
Timestamp ts = v.getTimestamp();
writeLong(ts.getTime());
writeLong(DateTimeUtils.getTimeLocalWithoutDst(ts));
writeInt(ts.getNanos() % 1_000_000);
}
break;
......@@ -555,28 +547,24 @@ public class Transfer {
case Value.DATE:
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueDate.fromDateValue(readLong());
} else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
} else {
return ValueDate.fromMillis(DateTimeUtils.getTimeUTCWithoutDst(readLong()));
}
return ValueDate.fromMillis(readLong());
case Value.TIME:
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueTime.fromNanos(readLong());
} else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
} else {
return ValueTime.fromMillis(DateTimeUtils.getTimeUTCWithoutDst(readLong()));
}
return ValueTime.fromMillis(readLong());
case Value.TIMESTAMP: {
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueTimestamp.fromDateValueAndNanos(
readLong(), readLong());
} else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
} else {
return ValueTimestamp.fromMillisNanos(
DateTimeUtils.getTimeUTCWithoutDst(readLong()),
readInt() % 1_000_000);
}
return ValueTimestamp.fromMillisNanos(readLong(),
readInt() % 1_000_000);
}
case Value.TIMESTAMP_TZ: {
return ValueTimestampTimeZone.fromDateValueAndNanos(readLong(),
......
......@@ -62,7 +62,7 @@ public class ValueTimestamp extends Value {
private ValueTimestamp(long dateValue, long timeNanos) {
this.dateValue = dateValue;
if (timeNanos < 0 || timeNanos >= 24L * 60 * 60 * 1000 * 1000 * 1000) {
if (timeNanos < 0 || timeNanos >= DateTimeUtils.NANOS_PER_DAY) {
throw new IllegalArgumentException("timeNanos out of range " + timeNanos);
}
this.timeNanos = timeNanos;
......@@ -229,7 +229,7 @@ public class ValueTimestamp extends Value {
long dv = dateValue;
if (n2 >= DateTimeUtils.NANOS_PER_DAY) {
n2 -= DateTimeUtils.NANOS_PER_DAY;
dv = DateTimeUtils.dateValueFromAbsoluteDay(DateTimeUtils.absoluteDayFromDateValue(dateValue) + 1);
dv = DateTimeUtils.incrementDateValue(dv);
}
return fromDateValueAndNanos(dv, n2);
}
......
......@@ -70,7 +70,7 @@ public class ValueTimestampTimeZone extends Value {
private ValueTimestampTimeZone(long dateValue, long timeNanos,
short timeZoneOffsetMins) {
if (timeNanos < 0 || timeNanos >= 24L * 60 * 60 * 1000 * 1000 * 1000) {
if (timeNanos < 0 || timeNanos >= DateTimeUtils.NANOS_PER_DAY) {
throw new IllegalArgumentException(
"timeNanos out of range " + timeNanos);
}
......@@ -218,7 +218,7 @@ public class ValueTimestampTimeZone extends Value {
long dv = dateValue;
if (n2 >= DateTimeUtils.NANOS_PER_DAY) {
n2 -= DateTimeUtils.NANOS_PER_DAY;
dv = DateTimeUtils.dateValueFromAbsoluteDay(DateTimeUtils.absoluteDayFromDateValue(dateValue) + 1);
dv = DateTimeUtils.incrementDateValue(dv);
}
return fromDateValueAndNanos(dv, n2, timeZoneOffsetMins);
}
......@@ -228,25 +228,25 @@ public class ValueTimestampTimeZone extends Value {
ValueTimestampTimeZone t = (ValueTimestampTimeZone) o;
// Maximum time zone offset is +/-18 hours so difference in days between local
// and UTC cannot be more than one day
long daysA = DateTimeUtils.absoluteDayFromDateValue(dateValue);
long dateValueA = dateValue;
long timeA = timeNanos - timeZoneOffsetMins * 60_000_000_000L;
if (timeA < 0) {
timeA += DateTimeUtils.NANOS_PER_DAY;
daysA--;
dateValueA = DateTimeUtils.decrementDateValue(dateValueA);
} else if (timeA >= DateTimeUtils.NANOS_PER_DAY) {
timeA -= DateTimeUtils.NANOS_PER_DAY;
daysA++;
dateValueA = DateTimeUtils.incrementDateValue(dateValueA);
}
long daysB = DateTimeUtils.absoluteDayFromDateValue(t.dateValue);
long dateValueB = t.dateValue;
long timeB = t.timeNanos - t.timeZoneOffsetMins * 60_000_000_000L;
if (timeB < 0) {
timeB += DateTimeUtils.NANOS_PER_DAY;
daysB--;
dateValueB = DateTimeUtils.decrementDateValue(dateValueB);
} else if (timeB >= DateTimeUtils.NANOS_PER_DAY) {
timeB -= DateTimeUtils.NANOS_PER_DAY;
daysB++;
dateValueB = DateTimeUtils.incrementDateValue(dateValueB);
}
int cmp = Long.compare(daysA, daysB);
int cmp = Long.compare(dateValueA, dateValueB);
if (cmp != 0) {
return cmp;
}
......
......@@ -377,6 +377,9 @@ public class TestDate extends TestBase {
assertEquals(y, DateTimeUtils.yearFromDateValue(date));
assertEquals(m, DateTimeUtils.monthFromDateValue(date));
assertEquals(d, DateTimeUtils.dayFromDateValue(date));
long nextDateValue = DateTimeUtils.dateValueFromAbsoluteDay(next);
assertEquals(nextDateValue, DateTimeUtils.incrementDateValue(date));
assertEquals(date, DateTimeUtils.decrementDateValue(nextDateValue));
}
}
}
......
......@@ -766,4 +766,4 @@ interpolated thead
die weekdiff osx subprocess dow proleptic microsecond microseconds divisible cmp denormalized suppressed saturated mcs
london dfs weekdays intermittent looked msec tstz africa monrovia asia tokyo weekday joi callers multipliers ucn
openoffice organize libre systemtables gmane sea borders announced millennium
openoffice organize libre systemtables gmane sea borders announced millennium alex nordlund rarely
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论