briangormanly / 4dflib

4DF (Fourth Dimensional Form) Library
http://www.4dflib.com
GNU Lesser General Public License v3.0
5 stars 4 forks source link

WhereClause Unary Operator #29

Closed blackjack26 closed 8 years ago

blackjack26 commented 8 years ago

When using the UNARY operator in a WhereClause, a null exception is thrown because the method getOperatorString() in WhereClause.java does not have a case statement for UNARY.

Corls commented 8 years ago

in the CoreMySqlQueries, you have

                // add the claus formatting the sql for the correct datatype
                if(clause.operator != WhereClause.Operators.UNARY) {
                    if (clause.value == WhereClause.NULL) {
                        sql += " " + clause.name + " " + clause.getOperatorString() + " " + clause.value + "";
                    } else if (clause.valueDataType == String.class) {
                        sql += " " + clause.name + " " + clause.getOperatorString() + " '" + clause.value + "'";
                    } else if (clause.valueDataType == int.class || clause.valueDataType == Integer.class ||
                            clause.valueDataType == long.class || clause.valueDataType == Long.class ||
                            clause.valueDataType == double.class || clause.valueDataType == Double.class ||
                            clause.valueDataType == float.class || clause.valueDataType == Float.class ||
                            clause.value2DataType == BigDecimal.class) {
                        sql += " " + clause.name + " " + clause.getOperatorString() + " " + clause.value;
                    } else if (clause.valueDataType == boolean.class || clause.valueDataType == Boolean.class) {
                        if (clause.value.toLowerCase().equals("true")) {
                            sql += " " + clause.name + " " + clause.getOperatorString() + " true";
                        } else if (clause.value.toLowerCase().equals("false")) {
                            sql += " " + clause.name + " " + clause.getOperatorString() + " false";
                        }
                    } else if (clause.valueDataType == Date.class) {
                        sql += " " + clause.name + " " + clause.getOperatorString() + " '" + clause.value + "'";
                    } else if (clause.valueDataType == UUID.class) {
                        sql += " " + clause.name + " " + clause.getOperatorString() + " '" + clause.value + "'";
                    } else {
                        sql += " " + clause.name + " " + clause.getOperatorString() + " '" + clause.value + "'";
                    }
                }```
Corls commented 8 years ago

it probably just wasn't copied over to the other CoreSqlQueries

blackjack26 commented 8 years ago

This function is missing the case for UNARY

public String getOperatorString() {

        switch (this.operator) {
            case EQUAL:
                return "=";

            case NOT_EQUAL:
                return "<>";

            case GREATER_THAN:
                return ">";

            case LESS_THAN:
                return "<";

            case GREATER_THAN_OR_EQUAL:
                return ">=";

            case LESS_THAN_OR_EQUAL:
                return "<=";

            case IN:
                return "IN";

            case BETWEEN:
                return "BETWEEN";

            case LIKE:
                return "LIKE";

            case IS:
                return "IS";

            case IS_NOT:
                return "IS NOT";

        }
        return null;
}