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

Return Value from Comparison.compareNotNull()

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