empire-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@glaubitz.org
Subject Re: Invert function
Date Fri, 30 Sep 2016 05:26:59 GMT
 

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?

You can extends DBColumnExpr and implement the addSQL method with
something like 

buf.append(getObjectValue(DataType.INTEGER, this.expr1, CTX_DEFAULT,
null));
 buf.append(" \ ");
 buf.append(getObjectValue(DataType.INTEGER, this.expr2, CTX_DEFAULT,
null)); 
and use it like 

DBInvertExpr inv = new DBInvertExpr(db, 1, T.DATA.VALUE);
DBCommand cmd = db.createCommand();
cmd.set(T.DATA.VALUE.to(inv));
cmd.where(T.DATA.KEY.is(23)); 

- jan 
 
Mime
View raw message