Object value;
int operator;
int counter2;
int counter = 0;
String queryValue = null;
DcField field;
DcModule m = DcModules.get(getModule());
for (DataFilterEntry entry : getEntries()) {
if (!m.isAbstract()) {
entryModule = DcModules.get(entry.getModule());
if (entry.getModule() != getModule()) {
childEntries.add(entry);
continue;
}
} else {
entryModule = module;
}
field = entryModule.getField(entry.getField());
if ( field.isUiOnly() &&
field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION &&
field.getValueType() != DcRepository.ValueTypes._PICTURE)
continue;
hasConditions = true;
operator = entry.getOperator().getIndex();
value = entry.getValue() != null ? Utilities.getQueryValue(entry.getValue(), field) : null;
if (value != null) {
queryValue = String.valueOf(value);
if (field.getValueType() == DcRepository.ValueTypes._DATE ||
field.getValueType() == DcRepository.ValueTypes._STRING) {
queryValue = queryValue.replaceAll("\'", "''");
}
}
if (counter > 0) sql.append(entry.isAnd() ? " AND " : " OR ");
if (counter == 0) sql.append(" WHERE ");
boolean useUpper = field.getValueType() == DcRepository.ValueTypes._STRING &&
field.getIndex() != DcObject._ID &&
field.getValueType() != DcRepository.ValueTypes._DCOBJECTREFERENCE &&
field.getValueType() != DcRepository.ValueTypes._DCPARENTREFERENCE &&
field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION;
if (field.getValueType() == DcRepository.ValueTypes._STRING) {
if (useUpper) sql.append("UPPER(");
sql.append(field.getDatabaseFieldName());
if (useUpper) sql.append(")");
} else if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION ||
field.getValueType() == DcRepository.ValueTypes._PICTURE) {
sql.append("ID");
} else {
sql.append(field.getDatabaseFieldName());
}
if (field.getValueType() == DcRepository.ValueTypes._PICTURE) {
if (operator == Operator.IS_EMPTY.getIndex())
sql.append(" NOT");
DcModule picModule = DcModules.get(DcModules._PICTURE);
sql.append(" IN (SELECT OBJECTID FROM " + picModule.getTableName() +
" WHERE " + picModule.getField(Picture._B_FIELD).getDatabaseFieldName() +
" = '" + field.getDatabaseFieldName() + "')");
} else if ( operator == Operator.CONTAINS.getIndex() ||
operator == Operator.DOES_NOT_CONTAIN.getIndex() ||
(operator == Operator.EQUAL_TO.getIndex() && field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) ||
(operator == Operator.NOT_EQUAL_TO.getIndex() && field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION)) {
if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
if (operator == Operator.DOES_NOT_CONTAIN.getIndex() ||
operator == Operator.NOT_EQUAL_TO.getIndex())
sql.append(" NOT");
sql.append(" IN (");
DcModule mapping = DcModules.get(DcModules.getMappingModIdx(entryModule.getIndex(), field.getReferenceIdx(), field.getIndex()));
sql.append("SELECT ");
sql.append(mapping.getField(DcMapping._A_PARENT_ID).getDatabaseFieldName());
sql.append(" FROM ");
sql.append(mapping.getTableName());
sql.append(" WHERE ");