empire-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Döbele <doeb...@esteam.de>
Subject re: Invert function
Date Mon, 03 Oct 2016 11:11:11 GMT
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: daniel.weidele@gmail.com [mailto:daniel.weidele@gmail.com]
> to: user@empire-db.apache.org
> 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

Mime
View raw message