提交 245aa770 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Return Value from Comparison.compareNotNull()

上级 eeace0e1
......@@ -294,7 +294,7 @@ public class Comparison extends Condition {
return ValueNull.INSTANCE;
}
}
return ValueBoolean.get(compareNotNull(database, l, r, compareType));
return compareNotNull(database, l, r, compareType);
}
/**
......@@ -304,11 +304,9 @@ public class Comparison extends Condition {
* @param l the first value
* @param r the second value
* @param compareType the compare type
* @return true if the comparison indicated by the comparison type evaluates
* to true
* @return result of comparison, either TRUE, FALSE, or NULL
*/
static boolean compareNotNull(Database database, Value l, Value r,
int compareType) {
static Value compareNotNull(Database database, Value l, Value r, int compareType) {
boolean result;
switch (compareType) {
case EQUAL:
......@@ -340,7 +338,7 @@ public class Comparison extends Condition {
default:
throw DbException.throwInternalError("type=" + compareType);
}
return result;
return ValueBoolean.get(result);
}
private int getReversedCompareType(int type) {
......
......@@ -59,24 +59,22 @@ public class ConditionIn extends Condition {
return ConditionInParameter.getValue(database, l, e.getValue(session));
}
}
boolean result = false;
boolean hasNull = false;
for (int i = 0; i < size; i++) {
Expression e = valueList.get(i);
Value r = e.getValue(session);
if (r == ValueNull.INSTANCE) {
Value cmp;
if (r == ValueNull.INSTANCE
|| (cmp = Comparison.compareNotNull(database, l, r, Comparison.EQUAL)) == ValueNull.INSTANCE) {
hasNull = true;
} else {
result = Comparison.compareNotNull(database, l, r, Comparison.EQUAL);
if (result) {
break;
} else if (cmp == ValueBoolean.TRUE) {
return cmp;
}
}
}
if (!result && hasNull) {
if (hasNull) {
return ValueNull.INSTANCE;
}
return ValueBoolean.get(result);
return ValueBoolean.FALSE;
}
@Override
......
......@@ -66,38 +66,35 @@ public class ConditionInParameter extends Condition {
private final Parameter parameter;
static Value getValue(Database database, Value l, Value value) {
boolean result = false;
boolean hasNull = false;
if (value == ValueNull.INSTANCE) {
hasNull = true;
} else if (value.getType() == Value.RESULT_SET) {
for (ResultInterface ri = value.getResult(); ri.next();) {
Value r = ri.currentRow()[0];
if (r == ValueNull.INSTANCE) {
Value cmp;
if (r == ValueNull.INSTANCE
|| (cmp = Comparison.compareNotNull(database, l, r, Comparison.EQUAL)) == ValueNull.INSTANCE) {
hasNull = true;
} else {
result = Comparison.compareNotNull(database, l, r, Comparison.EQUAL);
if (result) {
break;
}
} else if (cmp == ValueBoolean.TRUE) {
return cmp;
}
}
} else {
for (Value r : ((ValueArray) value.convertTo(Value.ARRAY)).getList()) {
if (r == ValueNull.INSTANCE) {
Value cmp;
if (r == ValueNull.INSTANCE
|| (cmp = Comparison.compareNotNull(database, l, r, Comparison.EQUAL)) == ValueNull.INSTANCE) {
hasNull = true;
} else {
result = Comparison.compareNotNull(database, l, r, Comparison.EQUAL);
if (result) {
break;
}
} else if (cmp == ValueBoolean.TRUE) {
return cmp;
}
}
}
if (!result && hasNull) {
if (hasNull) {
return ValueNull.INSTANCE;
}
return ValueBoolean.get(result);
return ValueBoolean.FALSE;
}
/**
......
......@@ -21,6 +21,7 @@ import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull;
import org.h2.value.ValueRow;
/**
* An 'in' condition with a subquery, as in WHERE ID IN(SELECT ...)
......@@ -88,30 +89,37 @@ public class ConditionInSelect extends Condition {
private Value getValueSlow(ResultInterface rows, Value l) {
// this only returns the correct result if the result has at least one
// row, and if l is not null
if (all) {
while (rows.next()) {
Value[] currentRow = rows.currentRow();
Value r = query.getColumnCount() == 1 ? currentRow[0] : ValueRow.get(currentRow);
Value cmp;
if (r == ValueNull.INSTANCE
|| (cmp = Comparison.compareNotNull(database, l, r, compareType)) == ValueNull.INSTANCE) {
return ValueNull.INSTANCE;
} else if (cmp == ValueBoolean.FALSE) {
return cmp;
}
}
return ValueBoolean.TRUE;
} else {
boolean hasNull = false;
boolean result = all;
while (rows.next()) {
boolean value;
Value[] currentRow = rows.currentRow();
Value r = query.getColumnCount() == 1 ? currentRow[0] : org.h2.value.ValueArray.get(currentRow);
if (r == ValueNull.INSTANCE) {
value = false;
Value r = query.getColumnCount() == 1 ? currentRow[0] : ValueRow.get(currentRow);
Value cmp;
if (r == ValueNull.INSTANCE
|| (cmp = Comparison.compareNotNull(database, l, r, compareType)) == ValueNull.INSTANCE) {
hasNull = true;
} else {
value = Comparison.compareNotNull(database, l, r, compareType);
} else if (cmp == ValueBoolean.TRUE) {
return cmp;
}
if (!value && all) {
result = false;
break;
} else if (value && !all) {
result = true;
break;
}
}
if (!result && hasNull) {
if (hasNull) {
return ValueNull.INSTANCE;
}
return ValueBoolean.get(result);
return ValueBoolean.FALSE;
}
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论