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