提交 41af1194 authored 作者: andrei's avatar andrei

Merge remote-tracking branch 'h2database/master' into test_out_of_memory

......@@ -2300,9 +2300,9 @@ Each table has a pseudo-column named ""_ROWID_"" that contains the unique row id
"
"Other Grammar","Time","
TIME 'hh:mm:ss'
TIME 'hh:mm:ss[.nnnnnnnnn]'
","
A time literal. A value is between plus and minus 2 million hours
A time literal. A value is between 0:00:00 and 23:59:59.999999999
and has nanosecond resolution.
","
TIME '23:59:59'
......@@ -2318,6 +2318,19 @@ minimum and maximum years are 0001 and 9999.
TIMESTAMP '2005-12-31 23:59:59'
"
"Other Grammar","Timestamp with time zone","
TIMESTAMP 'yyyy-MM-dd hh:mm:ss[.nnnnnnnnn]
[Z | { - | + } timeZoneOffsetString | timeZoneNameString ]'
","
A timestamp with time zone literal.
If name of time zone is specified it will be converted to time zone offset.
","
TIMESTAMP WITH TIME ZONE '2005-12-31 23:59:59Z'
TIMESTAMP WITH TIME ZONE '2005-12-31 23:59:59-10:00'
TIMESTAMP WITH TIME ZONE '2005-12-31 23:59:59.123+05'
TIMESTAMP WITH TIME ZONE '2005-12-31 23:59:59.123456789 Europe/London'
"
"Other Grammar","Value","
string | dollarQuotedString | numeric | date | time | timestamp | boolean | bytes | array | null
","
......@@ -3671,7 +3684,7 @@ CURRENT_TIMESTAMP()
Adds units to a date-time value. The string indicates the unit.
Use negative values to subtract units.
addIntLong may be a long value when manipulating milliseconds,
otherwise it's range is restricted to int.
microseconds, or nanoseconds otherwise its range is restricted to int.
The same units as in the EXTRACT function are supported.
This method returns a value with the same type as specified value if unit is compatible with this value.
If specified unit is a HOUR, MINUTE, SECOND, MILLISECOND, etc and value is a DATE value DATEADD returns combined TIMESTAMP.
......@@ -3727,11 +3740,13 @@ DAY_OF_YEAR(CREATED)
"Functions (Time and Date)","EXTRACT","
EXTRACT ( { YEAR | YY | MONTH | MM | QUARTER | WEEK | ISO_WEEK
| DAY | DD | DAY_OF_YEAR | DOY
| HOUR | HH | MINUTE | MI | SECOND | SS | MILLISECOND | MS }
| HOUR | HH | MINUTE | MI | SECOND | SS | EPOCH
| MILLISECOND | MS | MICROSECOND | MCS | NANOSECOND | NS }
FROM timestamp )
","
Returns a specific value from a timestamps.
This method returns an int.
This method returns a numeric value with EPOCH unit and
an int for all other time units.
","
EXTRACT(SECOND FROM CURRENT_TIMESTAMP)
"
......@@ -3820,6 +3835,17 @@ This method uses the current system locale.
WEEK(CREATED)
"
"Functions (Time and Date)","ISO_WEEK","
ISO_WEEK(timestamp)
","
Returns the week (1-53) from a timestamp.
This method uses the ISO definition when
first week of year should have at least four days
and week is started with Monday.
","
ISO_WEEK(CREATED)
"
"Functions (Time and Date)","YEAR","
YEAR(timestamp)
","
......@@ -3828,6 +3854,14 @@ Returns the year from a timestamp.
YEAR(CREATED)
"
"Functions (Time and Date)","ISO_YEAR","
ISO_YEAR(timestamp)
","
Returns the ISO week year from a timestamp.
","
ISO_YEAR(CREATED)
"
"Functions (System)","ARRAY_GET","
ARRAY_GET(arrayExpression, indexExpression)
","
......
......@@ -10,7 +10,6 @@ import org.h2.engine.DbObject;
import org.h2.engine.Session;
import org.h2.expression.ExpressionVisitor;
import org.h2.index.Index;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.result.Row;
import org.h2.schema.Schema;
......
......@@ -111,14 +111,9 @@ public class Function extends Expression implements FunctionCall {
ISO_WEEK = 124, ISO_DAY_OF_WEEK = 125;
/**
* Pseudo function for {@code EXTRACT(MILLISECOND FROM ...)}.
* Pseudo functions for DATEADD, DATEDIFF, and EXTRACT.
*/
public static final int MILLISECOND = 126;
/**
* Pseudo function for {@code EXTRACT(EPOCH FROM ...)}.
*/
public static final int EPOCH = 127;
public static final int MILLISECOND = 126, EPOCH = 127, MICROSECOND = 128, NANOSECOND = 129;
public static final int DATABASE = 150, USER = 151, CURRENT_USER = 152,
IDENTITY = 153, SCOPE_IDENTITY = 154, AUTOCOMMIT = 155,
......@@ -206,6 +201,10 @@ public class Function extends Expression implements FunctionCall {
DATE_PART.put("MILLISECOND", MILLISECOND);
DATE_PART.put("MS", MILLISECOND);
DATE_PART.put("EPOCH", EPOCH);
DATE_PART.put("MICROSECOND", MICROSECOND);
DATE_PART.put("MCS", MICROSECOND);
DATE_PART.put("NANOSECOND", NANOSECOND);
DATE_PART.put("NS", NANOSECOND);
// SOUNDEX_INDEX
String index = "7AEIOUY8HW1BFPV2CGJKQSXZ3DT4L5MN6R";
......@@ -864,7 +863,7 @@ public class Function extends Expression implements FunctionCall {
case SECOND:
case WEEK:
case YEAR:
result = ValueInt.get(getDatePart(v0, info.type));
result = ValueInt.get(getIntDatePart(v0, info.type));
break;
case MONTH_NAME: {
SimpleDateFormat monthName = new SimpleDateFormat("MMMM",
......@@ -1502,14 +1501,10 @@ public class Function extends Expression implements FunctionCall {
break;
case EXTRACT: {
int field = getDatePart(v0.getString());
// Normal case when we don't retrieve the EPOCH time
if (field != EPOCH) {
result = ValueInt.get(getDatePart(v1, field));
result = ValueInt.get(getIntDatePart(v1, field));
} else {
// Case where we retrieve the EPOCH time.
// First we retrieve the dateValue and his time in nanoseconds.
long[] a = DateTimeUtils.dateAndTimeFromValue(v1);
......@@ -1520,37 +1515,40 @@ public class Function extends Expression implements FunctionCall {
BigDecimal numberOfDays = new BigDecimal(DateTimeUtils.absoluteDayFromDateValue(dateValue));
BigDecimal nanosSeconds = new BigDecimal(1_000_000_000);
BigDecimal secondsPerDay = new BigDecimal(DateTimeUtils.SECONDS_PER_DAY);
// Case where the value is of type time e.g. '10:00:00'
if (v1 instanceof ValueTime) {
// In order to retrieve the EPOCH time we only have to convert the time
// In order to retrieve the EPOCH time we only have to convert the time
// in nanoseconds (previously retrieved) in seconds.
result = ValueDecimal.get(timeNanosBigDecimal.divide(nanosSeconds));
} else if (v1 instanceof ValueDate) {
// Case where the value is of type date '2000:01:01', we have to retrieve the total
// number of days and multiply it by the number of seconds in a day.
// Case where the value is of type date '2000:01:01', we have to retrieve the
// total number of days and multiply it by the number of seconds in a day.
result = ValueDecimal.get(numberOfDays.multiply(secondsPerDay));
} else if (v1 instanceof ValueTimestampTimeZone) {
// Case where the value is a of type ValueTimestampTimeZone ('2000:01:01 10:00:00+05).
// We retrieve the time zone offset in minute
// Case where the value is a of type ValueTimestampTimeZone
// ('2000:01:01 10:00:00+05').
// We retrieve the time zone offset in minutes
ValueTimestampTimeZone v = (ValueTimestampTimeZone) v1;
BigDecimal timeZoneOffsetSeconds = new BigDecimal(v.getTimeZoneOffsetMins() * 60);
// Sum the time in nanoseconds and the total number of days in seconds
// Sum the time in nanoseconds and the total number of days in seconds
// and adding the timeZone offset in seconds.
result = ValueDecimal.get(timeNanosBigDecimal.divide(nanosSeconds)
.add(numberOfDays.multiply(secondsPerDay))
.subtract(timeZoneOffsetSeconds));
.add(numberOfDays.multiply(secondsPerDay)).subtract(timeZoneOffsetSeconds));
} else {
// By default, we have the date and the time ('2000:01:01 10:00:00) if no type is given.
// We just have to sum the time in nanoseconds and the total number of days in seconds.
result = ValueDecimal.get(timeNanosBigDecimal.divide(nanosSeconds).add(numberOfDays.multiply(secondsPerDay)));
// By default, we have the date and the time ('2000:01:01 10:00:00') if no type
// is given.
// We just have to sum the time in nanoseconds and the total number of days in
// seconds.
result = ValueDecimal
.get(timeNanosBigDecimal.divide(nanosSeconds).add(numberOfDays.multiply(secondsPerDay)));
}
}
break;
......@@ -1866,8 +1864,7 @@ public class Function extends Expression implements FunctionCall {
private static Value dateadd(String part, long count, Value v) {
int field = getDatePart(part);
//v = v.convertTo(Value.TIMESTAMP);
if (field != MILLISECOND &&
if (field != MILLISECOND && field != MICROSECOND && field != NANOSECOND &&
(count > Integer.MAX_VALUE || count < Integer.MIN_VALUE)) {
throw DbException.getInvalidValueException("DATEADD count", count);
}
......@@ -1917,11 +1914,17 @@ public class Function extends Expression implements FunctionCall {
count *= 60_000_000_000L;
break;
case SECOND:
case EPOCH:
count *= 1_000_000_000;
break;
case MILLISECOND:
count *= 1_000_000;
break;
case MICROSECOND:
count *= 1_000;
break;
case NANOSECOND:
break;
default:
throw DbException.getUnsupportedException("DATEADD " + part);
}
......@@ -1966,17 +1969,27 @@ public class Function extends Expression implements FunctionCall {
long dateValue2 = a2[0];
long absolute2 = DateTimeUtils.absoluteDayFromDateValue(dateValue2);
switch (field) {
case NANOSECOND:
case MICROSECOND:
case MILLISECOND:
case SECOND:
case EPOCH:
case MINUTE:
case HOUR:
long timeNanos1 = a1[1];
long timeNanos2 = a2[1];
switch (field) {
case NANOSECOND:
return (absolute2 - absolute1) * DateTimeUtils.NANOS_PER_DAY
+ (timeNanos2 - timeNanos1);
case MICROSECOND:
return (absolute2 - absolute1) * (DateTimeUtils.MILLIS_PER_DAY * 1_000)
+ (timeNanos2 / 1_000 - timeNanos1 / 1_000);
case MILLISECOND:
return (absolute2 - absolute1) * DateTimeUtils.MILLIS_PER_DAY
+ (timeNanos2 / 1_000_000 - timeNanos1 / 1_000_000);
case SECOND:
case EPOCH:
return (absolute2 - absolute1) * 86_400
+ (timeNanos2 / 1_000_000_000 - timeNanos1 / 1_000_000_000);
case MINUTE:
......@@ -2859,7 +2872,7 @@ public class Function extends Expression implements FunctionCall {
* @param field the field type, see {@link Function} for constants
* @return the value
*/
public static int getDatePart(Value date, int field) {
public static int getIntDatePart(Value date, int field) {
long[] a = DateTimeUtils.dateAndTimeFromValue(date);
long dateValue = a[0];
long timeNanos = a[1];
......@@ -2878,6 +2891,10 @@ public class Function extends Expression implements FunctionCall {
return (int) (timeNanos / 1_000_000_000 % 60);
case Function.MILLISECOND:
return (int) (timeNanos / 1_000_000 % 1_000);
case Function.MICROSECOND:
return (int) (timeNanos / 1_000 % 1_000_000);
case Function.NANOSECOND:
return (int) (timeNanos % 1_000_000_000);
case Function.DAY_OF_YEAR:
return DateTimeUtils.getDayOfYear(dateValue);
case Function.DAY_OF_WEEK:
......
......@@ -171,7 +171,7 @@ public class DataReader extends Reader {
int i = 0;
try {
for (; i < len; i++) {
buff[i] = readChar();
buff[off + i] = readChar();
}
return len;
} catch (EOFException e) {
......
......@@ -1615,7 +1615,7 @@ public class MetaTable extends Table {
if (constraintType == Constraint.Type.CHECK) {
checkExpression = ((ConstraintCheck) constraint).getExpression().getSQL();
} else if (constraintType == Constraint.Type.UNIQUE ||
constraintType == Constraint.Type.PRIMARY_KEY) {
constraintType == Constraint.Type.PRIMARY_KEY) {
indexColumns = ((ConstraintUnique) constraint).getColumns();
} else if (constraintType == Constraint.Type.REFERENTIAL) {
indexColumns = ((ConstraintReferential) constraint).getColumns();
......
......@@ -224,7 +224,8 @@ public class ChangeFileEncryption extends Tool {
try (FileChannel fileIn = getFileChannel(fileName, "r", decryptKey)){
try(InputStream inStream = new FileChannelInputStream(fileIn, true)) {
FileUtils.delete(temp);
try (OutputStream outStream = new FileChannelOutputStream(getFileChannel(temp, "rw", encryptKey), true)) {
try (OutputStream outStream = new FileChannelOutputStream(getFileChannel(temp, "rw", encryptKey),
true)) {
byte[] buffer = new byte[4 * 1024];
long remaining = fileIn.size();
long total = remaining;
......
......@@ -36,7 +36,7 @@ public class DateTimeUtils {
* The number of milliseconds per day.
*/
public static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L;
/**
* The number of seconds per day.
*/
......@@ -921,19 +921,6 @@ public class DateTimeUtils {
return new Date(millis);
}
/**
* Convert an encoded date value to millis, using the supplied timezone.
*
* @param tz the timezone
* @param dateValue the date value
* @return the date
*/
public static long convertDateValueToMillis(TimeZone tz, long dateValue) {
return getMillis(tz, yearFromDateValue(dateValue),
monthFromDateValue(dateValue), dayFromDateValue(dateValue), 0,
0, 0, 0);
}
/**
* Convert an encoded date-time value to millis, using the supplied timezone.
*
......
......@@ -14,7 +14,6 @@ import java.io.Reader;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
......@@ -463,10 +462,6 @@ public class Transfer {
throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "length=" + length);
}
if (length > Integer.MAX_VALUE) {
throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "length="+ length);
}
writeLong(length);
Reader reader = v.getReader();
Data.copyString(reader, out);
......@@ -652,21 +647,10 @@ public class Transfer {
return ValueLobDb.create(
Value.CLOB, session.getDataHandler(), tableId, id, hmac, precision);
}
if (length < 0 || length > Integer.MAX_VALUE) {
if (length < 0) {
throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "length="+ length);
}
DataReader reader = new DataReader(in);
int len = (int) length;
char[] buff = new char[len];
IOUtils.readFully(reader, buff, len);
int magic = readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(
ErrorCode.CONNECTION_BROKEN_1, "magic=" + magic);
}
byte[] small = new String(buff).getBytes(StandardCharsets.UTF_8);
return ValueLobDb.createSmallLob(Value.CLOB, small, length);
}
Value v = session.getDataHandler().getLobStorage().
createClob(new DataReader(in), length);
......
......@@ -26,6 +26,7 @@ import org.h2.store.FileStoreInputStream;
import org.h2.store.FileStoreOutputStream;
import org.h2.store.LobStorageFrontend;
import org.h2.store.LobStorageInterface;
import org.h2.store.RangeReader;
import org.h2.store.fs.FileUtils;
import org.h2.util.IOUtils;
import org.h2.util.MathUtils;
......@@ -544,6 +545,15 @@ public class ValueLobDb extends Value implements Value.ValueClob,
*/
public static ValueLobDb createTempClob(Reader in, long length,
DataHandler handler) {
if (length >= 0) {
// Otherwise BufferedReader may try to read more data than needed and that
// blocks the network level
try {
in = new RangeReader(in, 0, length);
} catch (IOException e) {
throw DbException.convert(e);
}
}
BufferedReader reader;
if (in instanceof BufferedReader) {
reader = (BufferedReader) in;
......
......@@ -219,34 +219,31 @@ public class ValueTimestampTimeZone extends Value {
@Override
protected int compareSecure(Value o, CompareMode mode) {
ValueTimestampTimeZone t = (ValueTimestampTimeZone) o;
// We are pretending that the dateValue is in UTC because that gives us
// a stable sort even if the DST database changes.
// convert to minutes and add timezone offset
long a = DateTimeUtils.convertDateValueToMillis(
DateTimeUtils.UTC, dateValue) /
(1000L * 60L);
long ma = timeNanos / (1000L * 1000L * 1000L * 60L);
a += ma;
a -= timeZoneOffsetMins;
// convert to minutes and add timezone offset
long b = DateTimeUtils.convertDateValueToMillis(
DateTimeUtils.UTC, t.dateValue) /
(1000L * 60L);
long mb = t.timeNanos / (1000L * 1000L * 1000L * 60L);
b += mb;
b -= t.timeZoneOffsetMins;
// compare date
int c = Long.compare(a, b);
if (c != 0) {
return c;
// 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 timeA = timeNanos - timeZoneOffsetMins * 60_000_000_000L;
if (timeA < 0) {
timeA += DateTimeUtils.NANOS_PER_DAY;
daysA--;
} else if (timeA >= DateTimeUtils.NANOS_PER_DAY) {
timeA -= DateTimeUtils.NANOS_PER_DAY;
daysA++;
}
long daysB = DateTimeUtils.absoluteDayFromDateValue(t.dateValue);
long timeB = t.timeNanos - t.timeZoneOffsetMins * 60_000_000_000L;
if (timeB < 0) {
timeB += DateTimeUtils.NANOS_PER_DAY;
daysB--;
} else if (timeB >= DateTimeUtils.NANOS_PER_DAY) {
timeB -= DateTimeUtils.NANOS_PER_DAY;
daysB++;
}
int cmp = Long.compare(daysA, daysB);
if (cmp != 0) {
return cmp;
}
// compare time
long na = timeNanos - (ma * 1000L * 1000L * 1000L * 60L);
long nb = t.timeNanos - (mb * 1000L * 1000L * 1000L * 60L);
return Long.compare(na, nb);
return Long.compare(timeA, timeB);
}
@Override
......
......@@ -466,16 +466,16 @@ public abstract class TestBase {
throw new AssertionError(string);
}
/**
* Log an error message.
*
* @param s the message
*/
public static void logErrorMessage(String s) {
System.out.flush();
System.err.println("ERROR: " + s + "------------------------------");
logThrowable(s, null);
}
/**
* Log an error message.
*
* @param s the message
*/
public static void logErrorMessage(String s) {
System.out.flush();
System.err.println("ERROR: " + s + "------------------------------");
logThrowable(s, null);
}
/**
* Log an error message.
......
......@@ -119,7 +119,20 @@ public class TestLobApi extends TestBase {
prep.setString(1, "");
prep.setBytes(2, new byte[0]);
prep.execute();
Random r = new Random(1);
char[] charsSmall = new char[20];
for (int i = 0; i < charsSmall.length; i++) {
charsSmall[i] = (char) r.nextInt(10000);
}
String dSmall = new String(charsSmall);
prep.setCharacterStream(1, new StringReader(dSmall), -1);
byte[] bytesSmall = new byte[20];
r.nextBytes(bytesSmall);
prep.setBinaryStream(2, new ByteArrayInputStream(bytesSmall), -1);
prep.execute();
char[] chars = new char[100000];
for (int i = 0; i < chars.length; i++) {
chars[i] = (char) r.nextInt(10000);
......@@ -130,6 +143,7 @@ public class TestLobApi extends TestBase {
r.nextBytes(bytes);
prep.setBinaryStream(2, new ByteArrayInputStream(bytes), -1);
prep.execute();
conn.setAutoCommit(false);
ResultSet rs = stat.executeQuery("select * from test order by id");
rs.next();
......@@ -138,18 +152,27 @@ public class TestLobApi extends TestBase {
rs.next();
Clob c2 = rs.getClob(2);
Blob b2 = rs.getBlob(3);
rs.next();
Clob c3 = rs.getClob(2);
Blob b3 = rs.getBlob(3);
assertFalse(rs.next());
// now close
rs.close();
// but the LOBs must stay open
assertEquals(0, c1.length());
assertEquals(0, b1.length());
assertEquals(chars.length, c2.length());
assertEquals(bytes.length, b2.length());
assertEquals("", c1.getSubString(1, 0));
assertEquals(new byte[0], b1.getBytes(1, 0));
assertEquals(d, c2.getSubString(1, (int) c2.length()));
assertEquals(bytes, b2.getBytes(1, (int) b2.length()));
assertEquals(charsSmall.length, c2.length());
assertEquals(bytesSmall.length, b2.length());
assertEquals(dSmall, c2.getSubString(1, (int) c2.length()));
assertEquals(bytesSmall, b2.getBytes(1, (int) b2.length()));
assertEquals(chars.length, c3.length());
assertEquals(bytes.length, b3.length());
assertEquals(d, c3.getSubString(1, (int) c3.length()));
assertEquals(bytes, b3.getBytes(1, (int) b3.length()));
stat.execute("drop table test");
conn.close();
}
......
......@@ -92,7 +92,7 @@ public class TestScript extends TestBase {
} else {
decimal2 = "decimal_numeric";
}
for (String s : new String[] { "array", "bigint", "binary", "blob",
"boolean", "char", "clob", "date", "decimal", decimal2, "double", "enum",
"geometry", "identity", "int", "other", "real", "smallint",
......
......@@ -105,6 +105,18 @@ call dateadd('MS', 1, TIMESTAMP '2001-02-03 04:05:06.789001');
> 2001-02-03 04:05:06.790001
> rows: 1
SELECT DATEADD('MICROSECOND', 1, TIME '10:00:01'), DATEADD('MCS', 1, TIMESTAMP '2010-10-20 10:00:01.1');
> TIME '10:00:01.000001' TIMESTAMP '2010-10-20 10:00:01.100001'
> ---------------------- --------------------------------------
> 10:00:01.000001 2010-10-20 10:00:01.100001
> rows: 1
SELECT DATEADD('NANOSECOND', 1, TIME '10:00:01'), DATEADD('NS', 1, TIMESTAMP '2010-10-20 10:00:01.1');
> TIME '10:00:01.000000001' TIMESTAMP '2010-10-20 10:00:01.100000001'
> ------------------------- -----------------------------------------
> 10:00:01.000000001 2010-10-20 10:00:01.100000001
> rows: 1
SELECT DATEADD('HOUR', 1, DATE '2010-01-20');
> TIMESTAMP '2010-01-20 01:00:00.0'
> ---------------------------------
......
......@@ -159,6 +159,22 @@ call datediff('MS', TIMESTAMP '1900-01-01 00:00:01.000', TIMESTAMP '2008-01-01 0
> 3408134399000
> rows: 1
SELECT DATEDIFF('MICROSECOND', '2006-01-01 00:00:00.0000000', '2006-01-01 00:00:00.123456789'),
DATEDIFF('MCS', '2006-01-01 00:00:00.0000000', '2006-01-01 00:00:00.123456789'),
DATEDIFF('MCS', '2006-01-01 00:00:00.0000000', '2006-01-02 00:00:00.123456789');
> 123456 123456 86400123456
> ------ ------ -----------
> 123456 123456 86400123456
> rows: 1
SELECT DATEDIFF('NANOSECOND', '2006-01-01 00:00:00.0000000', '2006-01-01 00:00:00.123456789'),
DATEDIFF('NS', '2006-01-01 00:00:00.0000000', '2006-01-01 00:00:00.123456789'),
DATEDIFF('NS', '2006-01-01 00:00:00.0000000', '2006-01-02 00:00:00.123456789');
> 123456789 123456789 86400123456789
> --------- --------- --------------
> 123456789 123456789 86400123456789
> rows: 1
SELECT DATEDIFF('WEEK', DATE '2018-02-02', DATE '2018-02-03'), DATEDIFF('ISO_WEEK', DATE '2018-02-02', DATE '2018-02-03');
> 0 0
> - -
......
......@@ -3,6 +3,20 @@
-- Initial Developer: H2 Group
--
SELECT EXTRACT (MICROSECOND FROM TIME '10:00:00.123456789'),
EXTRACT (MCS FROM TIMESTAMP '2015-01-01 11:22:33.987654321');
> 123456 987654
> ------ ------
> 123456 987654
> rows: 1
SELECT EXTRACT (NANOSECOND FROM TIME '10:00:00.123456789'),
EXTRACT (NS FROM TIMESTAMP '2015-01-01 11:22:33.987654321');
> 123456789 987654321
> --------- ---------
> 123456789 987654321
> rows: 1
select EXTRACT (EPOCH from time '00:00:00');
> 0
......
......@@ -119,7 +119,7 @@ public class TestFuzzOptimizations extends TestBase {
}
}
executeAndCompare("a >=0 and b in(?, 2) and a in(1, ?, null)", Arrays.asList("10", "2"),
"seed=-6191135606105920350L");
"seed=-6191135606105920350L");
db.execute("drop table test0, test1");
}
......
......@@ -5,14 +5,12 @@
*/
package org.h2.test.unit;
import static org.h2.util.DateTimeUtils.dateValue;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.h2.test.TestBase;
import org.h2.util.DateTimeUtils;
import static org.h2.util.DateTimeUtils.dateValue;
/**
* Unit tests for the DateTimeUtils class
*/
......@@ -44,7 +42,7 @@ public class TestDateTimeUtils extends TestBase {
}
/**
* Test for {@link DateTimeUtils#getSundayDayOfWeek()} and
* Test for {@link DateTimeUtils#getSundayDayOfWeek(long)} and
* {@link DateTimeUtils#getIsoDayOfWeek(long)}.
*/
private void testDayOfWeek() {
......
......@@ -126,21 +126,27 @@ public class TestTimeStampWithTimeZone extends TestBase {
ValueTimestampTimeZone a = ValueTimestampTimeZone.parse("1970-01-01 12:00:00.00+00:15");
ValueTimestampTimeZone b = ValueTimestampTimeZone.parse("1970-01-01 12:00:01.00+01:15");
int c = a.compareTo(b, null);
assertEquals(c, 1);
assertEquals(1, c);
c = b.compareTo(a, null);
assertEquals(-1, c);
}
private void test3() {
ValueTimestampTimeZone a = ValueTimestampTimeZone.parse("1970-01-02 00:00:02.00+01:15");
ValueTimestampTimeZone b = ValueTimestampTimeZone.parse("1970-01-01 23:00:01.00+00:15");
int c = a.compareTo(b, null);
assertEquals(c, 1);
assertEquals(1, c);
c = b.compareTo(a, null);
assertEquals(-1, c);
}
private void test4() {
ValueTimestampTimeZone a = ValueTimestampTimeZone.parse("1970-01-02 00:00:01.00+01:15");
ValueTimestampTimeZone b = ValueTimestampTimeZone.parse("1970-01-01 23:00:01.00+00:15");
int c = a.compareTo(b, null);
assertEquals(c, 0);
assertEquals(0, c);
c = b.compareTo(a, null);
assertEquals(0, c);
}
private void test5() throws SQLException {
......
......@@ -764,5 +764,5 @@ mdy destfile hclf forbids spellchecking selfdestruct expects accident jacocoagen
jacoco xdata invokes sourcefiles classfiles duplication crypto stacktraces prt directions handled overly asm hardcoded
interpolated thead
die weekdiff osx subprocess dow proleptic
die weekdiff osx subprocess dow proleptic microsecond microseconds divisible cmp denormalized suppressed saturated mcs
london
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论