提交 542e981f authored 作者: Owner's avatar Owner

Issue#458 TIMESTAMPDIFF YEAR fix plus show all TestScriptSimple failures

上级 5592109a
......@@ -1886,11 +1886,11 @@ public class Function extends Expression implements FunctionCall {
calendar.setTimeInMillis(t2);
int year2 = calendar.get(Calendar.YEAR);
int month2 = calendar.get(Calendar.MONTH);
int result = year2 - year1;
int yearResult = year2 - year1;
if (field == Calendar.MONTH) {
return 12 * result + (month2 - month1);
return 12 * yearResult + (month2 - month1);
} else if (field == Calendar.YEAR) {
return result;
return (12 * yearResult + (month2 - month1))/12;
} else {
throw DbException.getUnsupportedException("DATEDIFF " + part);
}
......
......@@ -11,6 +11,9 @@ import java.io.LineNumberReader;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.h2.test.TestBase;
import org.h2.util.ScriptReader;
......@@ -42,6 +45,7 @@ public class TestScriptSimple extends TestBase {
InputStream is = getClass().getClassLoader().getResourceAsStream(inFile);
LineNumberReader lineReader = new LineNumberReader(
new InputStreamReader(is, "Cp1252"));
List<Throwable> exceptions = new ArrayList<>();
try (ScriptReader reader = new ScriptReader(lineReader)) {
while (true) {
String sql = reader.readStatement();
......@@ -64,14 +68,22 @@ public class TestScriptSimple extends TestBase {
} else {
conn.createStatement().execute(sql);
}
} catch (SQLException e) {
} catch (Throwable e) {
System.out.println(sql);
throw e;
System.out.println(" at line#"+lineReader.getLineNumber()+" of file "+inFile);
e.printStackTrace();
exceptions.add(e);
}
}
}
conn.close();
deleteDb("scriptSimple");
if(exceptions.size()!=0){
String message = "Failed test, detected assertions="+exceptions.size();
System.out.println(message);
throw new AssertionError(message);
}
}
private void reconnect() throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论