Hi, another solution
DBValueExpr v = db.getValueExpr(1, DataType.INTEGER); DBColumnExpr inv = v.divideBy(T.DATA_VALUE); DBCommand cmd = db.createCommand(); cmd.set(T.DATA.VALUE.to <http://t.data.value.to/>(inv)); cmd.where(T.DATA.KEY.is <http://t.data.key.is/>(23)); But if you use it many times, Jan's solution is better and much more elegant :). Regards, Ivan <[email protected]> ezt írta (időpont: 2016. szept. 30., P, 7:27): > 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 > >
