private Boolean getAnyAllValue(Session session, Object o,
SubQuery subquery) throws HsqlException {
boolean empty = subquery.table.isEmpty(session);
Index index = subquery.table.getPrimaryIndex();
RowIterator it = index.findFirstRowNotNull(session);
Row firstrow = it.next();
switch (eArg2.exprType) {
case ANY : {
if (empty) {
return Boolean.FALSE;
}
if (firstrow == null) {
return null;
}
int range =
Column.compareToTypeRange(o, eArg2.eArg.getDataType());
if (range != 0) {
switch (exprType) {
case EQUAL :
return Boolean.FALSE;
case NOT_EQUAL :
return Boolean.TRUE;
case BIGGER :
case BIGGER_EQUAL :
return range > 0 ? Boolean.TRUE
: Boolean.FALSE;
case SMALLER_EQUAL :
case SMALLER :
return range < 0 ? Boolean.TRUE
: Boolean.FALSE;
}
}
o = Column.convertObject(o, eArg2.eArg.getDataType());
if (exprType == EQUAL) {
it = index.findFirstRow(session, o, EQUAL);
return it.hasNext() ? Boolean.TRUE
: Boolean.FALSE;
}
Row lastrow = index.lastRow(session);
Object firstdata = firstrow.getData()[0];
Object lastdata = lastrow.getData()[0];
int comparefirst = Column.compare(session.database.collation,
o, firstdata,
eArg.getDataType());
int comparelast = Column.compare(session.database.collation,
o, lastdata,
eArg.getDataType());
switch (exprType) {
case NOT_EQUAL :
return (comparefirst == 0 && comparelast == 0)
? Boolean.FALSE
: Boolean.TRUE;
case BIGGER :
return comparefirst > 0 ? Boolean.TRUE
: Boolean.FALSE;
case BIGGER_EQUAL :
return comparefirst >= 0 ? Boolean.TRUE
: Boolean.FALSE;
case SMALLER :
return comparelast < 0 ? Boolean.TRUE
: Boolean.FALSE;
case SMALLER_EQUAL :
return comparelast <= 0 ? Boolean.TRUE
: Boolean.FALSE;
}
break;
}
case ALL : {
if (empty) {
return Boolean.TRUE;
}
if (firstrow == null) {
return null;
}
int range =
Column.compareToTypeRange(o, eArg2.eArg.getDataType());
if (range != 0) {
switch (exprType) {
case EQUAL :
return Boolean.FALSE;
case NOT_EQUAL :
return Boolean.TRUE;
case BIGGER :
case BIGGER_EQUAL :
return range > 0 ? Boolean.TRUE
: Boolean.FALSE;
case SMALLER_EQUAL :
case SMALLER :
return range < 0 ? Boolean.TRUE
: Boolean.FALSE;
}
}
o = Column.convertObject(o, eArg2.eArg.getDataType());
if (exprType == EQUAL || exprType == NOT_EQUAL) {
it = index.findFirstRow(session, o, EQUAL);
if (exprType == EQUAL) {
return (it.hasNext() && subquery.table.getRowCount(session) == 1)
? Boolean.TRUE
: Boolean.FALSE;
}
return (it.hasNext()) ? Boolean.FALSE
: Boolean.TRUE;
}
Row lastrow = index.lastRow(session);
Object firstdata = firstrow.getData()[0];