Unverified 提交 ab3f0cd8 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1669 from katzyn/compatibility

Ignore errors in MySQL compatibility DATE() function
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Issue #1668: MySQL compatibility DATE() function should return NULL on error
</li>
<li>Issue #1604: TestCrashAPI: PreparedStatement.getGeneratedKeys() is already closed <li>Issue #1604: TestCrashAPI: PreparedStatement.getGeneratedKeys() is already closed
</li> </li>
<li>PR #1667: Detect NULL values and overflow in window frame bounds <li>PR #1667: Detect NULL values and overflow in window frame bounds
......
...@@ -22,6 +22,7 @@ import org.h2.util.StringUtils; ...@@ -22,6 +22,7 @@ import org.h2.util.StringUtils;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
import org.h2.value.ValueNull;
import org.h2.value.ValueString; import org.h2.value.ValueString;
/** /**
...@@ -229,7 +230,11 @@ public class FunctionsMySQL extends FunctionsBase { ...@@ -229,7 +230,11 @@ public class FunctionsMySQL extends FunctionsBase {
result = v0; result = v0;
break; break;
default: default:
try {
v0 = v0.convertTo(Value.TIMESTAMP); v0 = v0.convertTo(Value.TIMESTAMP);
} catch (DbException ex) {
v0 = ValueNull.INSTANCE;
}
//$FALL-THROUGH$ //$FALL-THROUGH$
case Value.TIMESTAMP: case Value.TIMESTAMP:
case Value.TIMESTAMP_TZ: case Value.TIMESTAMP_TZ:
......
...@@ -312,16 +312,12 @@ public class TestCompatibility extends TestDb { ...@@ -312,16 +312,12 @@ public class TestCompatibility extends TestDb {
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"); stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')"); stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')");
assertResult("0", stat, "SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00Z')"); assertResult("0", stat, "SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00Z')");
assertResult("1196418619", stat, assertResult("1196418619", stat, "SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19Z')");
"SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19Z')"); assertResult("1196418619", stat, "SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(1196418619))");
assertResult("1196418619", stat, assertResult("2007 November", stat, "SELECT FROM_UNIXTIME(1196300000, '%Y %M')");
"SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(1196418619))"); assertResult("2003-12-31", stat, "SELECT DATE('2003-12-31 11:02:03')");
assertResult("2007 November", stat, assertResult("2003-12-31", stat, "SELECT DATE('2003-12-31 11:02:03')");
"SELECT FROM_UNIXTIME(1196300000, '%Y %M')"); assertResult(null, stat, "SELECT DATE('100')");
assertResult("2003-12-31", stat,
"SELECT DATE('2003-12-31 11:02:03')");
assertResult("2003-12-31", stat,
"SELECT DATE('2003-12-31 11:02:03')");
// check the weird MySQL variant of DELETE // check the weird MySQL variant of DELETE
stat.execute("DELETE TEST FROM TEST WHERE 1=2"); stat.execute("DELETE TEST FROM TEST WHERE 1=2");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论