Hi Daniel,

sorry for the late reply.
The intended way is to do it like this (similar to what Ivan wrote):

DBCommand cmd = db.createCommand();
cmd.set(db.EMPLOYEES.SALARY.to(db.getValueExpr(1).divideBy(db.EMPLOYEES.SALARY)));
cmd.where(db.EMPLOYEES.EMPLOYEE_ID.is(100));

That will give you:
                        
UPDATE EMPLOYEES
SET SALARY=1/SALARY
WHERE EMPLOYEE_ID=100

If you need it more often, then simply declare this class:

public class InvertExpr extends DBSetExpr
{
        public InvertExpr(DBColumn expr)
        {
                super(expr, expr.getDatabase().getValueExpr(1).divideBy(expr));
        }
}

Afterwards you can simply write:

cmd.set(new InvertExpr(db.EMPLOYEES.SALARY));

Hope this helps.

Regards
Rainer

> from: [email protected] [mailto:[email protected]]
> to: [email protected]
> subject: Invert function

> Hello,
> I would like to write a simple "invert" function for numeric columns via 
> EmpireDB.
> I am aware of the native SQL mechanism, but I was wondering if there is also 
> a way of making this "properly":
> UPDATE data SET value = 1 / value WHERE key = "someKey";
> Any ideas how to achieve this in EmpireDB?
> Cheers,
> Daniel

Reply via email to