Skip to content

Bug in Update(Table.class).Set() causes boolean parameters to be stored as strings #449

@vessnv

Description

@vessnv

I was running

new Update(Table.class).set("columnName = ?", false);
new Select().from(Table.class).where("columnName = ?", false);

The select returns 0 results. The issue is that Where actually looks at the parameter type and converts it correctly, whereas Set simply runs .toString() on all arguments, which results in booleans being stored in the db as true and false instead of 1 and 0.

This is from Set.java:

public String[] getArguments() {
    final int setSize = mSetArguments.size();
    final int whereSize = mWhereArguments.size();
    final String[] args = new String[setSize + whereSize];

    for (int i = 0; i < setSize; i++) {
        args[i] = mSetArguments.get(i).toString();
    }

    for (int i = 0; i < whereSize; i++) {
        args[i + setSize] = mWhereArguments.get(i).toString();
    }

    return args;
}

This is from From.java:

void addArguments(Object[] args) {
    for(Object arg : args) {
        if (arg.getClass() == boolean.class || arg.getClass() == Boolean.class) {
            arg = (arg.equals(true) ? 1 : 0);
        }
        mArguments.add(arg);
    }
}

Set needs to handle booleans like Where, otherwise you end up with a table that looks like this:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions