This commit is contained in:
yakolee
2014-06-06 18:43:49 +08:00
parent d20b1f684e
commit f8d2987931
2 changed files with 26 additions and 3 deletions
@@ -1418,6 +1418,18 @@ public class SQLEvalVisitorUtils {
if (a == null || b == null) {
return null;
}
if(a == EVAL_VALUE_NULL || b == EVAL_VALUE_NULL) {
return null;
}
if (a instanceof String) {
a = castToNumber((String) a);
}
if (b instanceof String) {
b = castToNumber((String) b);
}
if (a instanceof Long || b instanceof Long) {
return castToLong(a).longValue() & castToLong(b).longValue();
@@ -1503,7 +1515,18 @@ public class SQLEvalVisitorUtils {
}
if (a instanceof Long || b instanceof Long) {
return castToLong(a) / castToLong(b);
Long longA = castToLong(a);
Long longB = castToLong(b);
if (longB == 0) {
if (longA > 0) {
return Double.POSITIVE_INFINITY;
} else if (longA < 0) {
return Double.NEGATIVE_INFINITY;
} else {
return Double.NaN;
}
}
return longA / longB;
}
if (a instanceof Integer || b instanceof Integer) {
@@ -50,7 +50,7 @@ public class Substring implements Function {
if (paramSize == 2) {
if (index < 0) {
if (index <= 0) {
int lastIndex = str.length() + index;
return str.substring(lastIndex);
}
@@ -68,7 +68,7 @@ public class Substring implements Function {
int len = ((Number) param2Value).intValue();
String result;
if (index < 0) {
if (index <= 0) {
int lastIndex = str.length() + index;
result = str.substring(lastIndex);
} else {