提交 bbad6234 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Partially revert the previous commit

上级 61a0fcf6
......@@ -14,7 +14,6 @@ import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
......@@ -689,11 +688,6 @@ public class Utils {
return false;
}
}
try {
return new BigDecimal(value).signum() != 0;
} catch (NumberFormatException e) {
// Nothing to do
}
if (throwException) {
throw new IllegalArgumentException(value);
}
......
......@@ -31,7 +31,6 @@ import org.h2.util.DateTimeUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils;
import org.h2.util.StringUtils;
import org.h2.util.Utils;
/**
* This is the base class for all value classes.
......@@ -1012,10 +1011,19 @@ public abstract class Value {
case NULL:
return ValueNull.INSTANCE;
case BOOLEAN: {
try {
return ValueBoolean.get(Utils.parseBoolean(s, false, true));
} catch (IllegalArgumentException e) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, s);
if (s.equalsIgnoreCase("true") ||
s.equalsIgnoreCase("t") ||
s.equalsIgnoreCase("yes") ||
s.equalsIgnoreCase("y")) {
return ValueBoolean.get(true);
} else if (s.equalsIgnoreCase("false") ||
s.equalsIgnoreCase("f") ||
s.equalsIgnoreCase("no") ||
s.equalsIgnoreCase("n")) {
return ValueBoolean.get(false);
} else {
// convert to a number, and if it is not 0 then it is true
return ValueBoolean.get(new BigDecimal(s).signum() != 0);
}
}
case BYTE:
......
......@@ -265,11 +265,6 @@ public class TestUtils extends TestBase {
testParseBooleanCheckTrue("true");
testParseBooleanCheckTrue("True");
testParseBooleanCheckTrue("TRUE");
// Test numbers
testParseBooleanCheckFalse("0.0");
testParseBooleanCheckFalse("-0.0");
testParseBooleanCheckTrue("0.1");
testParseBooleanCheckTrue("-0.1");
// Test other values
assertFalse(Utils.parseBoolean("BAD", false, false));
assertTrue(Utils.parseBoolean("BAD", true, false));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论