You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@empire-db.apache.org by Ivan Nemeth <iv...@gmail.com> on 2016/09/08 14:58:43 UTC

Bug with DBColumnExpr.multiplyWith and divide

Hi,

(Rainer, couldn't create an issue in Jira, please can you check it?  (missing
permission maybe?))

Empire generates wrong sql if you multiply a DBCalcExpr with some value,
example:

DBDatabase db = new DBDatabase() {
};
db.open(new DBDatabaseDriverHSql(), null);
class Test extends DBTable {

final DBTableColumn A;
final DBTableColumn B;
public Test(String name, DBDatabase db) {
super(name, db);
A = addColumn("A", DataType.INTEGER, 64, true);
B = addColumn("B", DataType.INTEGER, 64, true);
}
}

Test T = new Test("test", db);
DBCommand cmd = db.createCommand();
*DBColumnExpr COL = T.A.plus(T.B).multiplyWith(2.0);*

cmd.select(COL);

System.out.println(cmd.getSelect());

The expected sql would be:

*SELECT (t1.A + t1.B) * 2.0 FROM test t1*

but Empire generates it with no parentheses

*SELECT t1.A + t1.B * 2.0 FROM test t1*

Solution would be to append parentheses in DBCalcExpr.addSql method
something like this (it is required only for * and / operators):

        *buf.append("(");*
        expr.addSQL(buf, context);
        *buf.append(")");  *
        buf.append(op);
        // Special treatment for adding days to dates
...

What do you think?


Regards,
Ivan