Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1F45E200BA0 for ; Fri, 30 Sep 2016 08:04:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 07DEE160AE4; Fri, 30 Sep 2016 06:04:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 25867160AE3 for ; Fri, 30 Sep 2016 08:04:47 +0200 (CEST) Received: (qmail 79672 invoked by uid 500); 30 Sep 2016 06:04:47 -0000 Mailing-List: contact user-help@empire-db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@empire-db.apache.org Delivered-To: mailing list user@empire-db.apache.org Received: (qmail 79662 invoked by uid 99); 30 Sep 2016 06:04:47 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Sep 2016 06:04:47 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id D7392180629 for ; Fri, 30 Sep 2016 06:04:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.48 X-Spam-Level: ** X-Spam-Status: No, score=2.48 tagged_above=-999 required=6.31 tests=[HEADER_FROM_DIFFERENT_DOMAINS=0.001, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id n_X_HmzhdyZw for ; Fri, 30 Sep 2016 06:04:43 +0000 (UTC) Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with ESMTPS id E2B0B5FADE for ; Fri, 30 Sep 2016 06:04:42 +0000 (UTC) Received: by mail-wm0-f51.google.com with SMTP id k125so4391564wma.1 for ; Thu, 29 Sep 2016 23:04:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=0BTtXCA5Vj25hTyHca9RPboRINKSAeL+4o2uu9klyLA=; b=UHkLHoR6554w5w0j8cEfJ3wFdSmgZUfz81/u+3GArAuxg8f6zu0Kr36iFsi92PJCep oxVHtjtTrHHSn50DPIM//Qoogwy9J3jNQAOnCRBB115pI1olyfj0lpkLrfI/wdRPswBR PxhUOJQ55X6J9YxvWC7aZnmbfBnUj/4Go1tYYccdcfhTIOR/iIqHKyj0OidWP90me2fZ dqkL9k1anZEQLkKFhF4MHYI3f/rDapdpiiI/dbhf6K0wdg8q7AGlKLxADSLemeDuQ2j2 5Hp9Gt/tZjvY1/ZunCGiaPsMDXiZwkAgMR2aAUYoBwtM742fF+L50IpVEqm9/qggQEXJ CMpQ== X-Gm-Message-State: AA6/9RmQG8Ak+/75P+zHqjfPWOyT+bxvKGrup9zt70B0pZaQKZNTAv+ha1TgWpa7cHyIxYgCnRRb1JuhVvrIXA== X-Received: by 10.194.47.101 with SMTP id c5mr4814673wjn.67.1475215482164; Thu, 29 Sep 2016 23:04:42 -0700 (PDT) MIME-Version: 1.0 References: <4991074c42a65e0e002d77d3b0e39f3e@glaubitz.org> In-Reply-To: <4991074c42a65e0e002d77d3b0e39f3e@glaubitz.org> From: ivan nemeth Date: Fri, 30 Sep 2016 06:04:31 +0000 Message-ID: Subject: Re: Invert function To: user@empire-db.apache.org Content-Type: multipart/alternative; boundary=047d7b86e992c81c74053db35e4c archived-at: Fri, 30 Sep 2016 06:04:49 -0000 --047d7b86e992c81c74053db35e4c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, another solution DBValueExpr v =3D db.getValueExpr(1, DataType.INTEGER); DBColumnExpr inv =3D v.divideBy(T.DATA_VALUE); DBCommand cmd =3D db.createCommand(); cmd.set(T.DATA.VALUE.to (inv)); cmd.where(T.DATA.KEY.is (23)); But if you use it many times, Jan's solution is better and much more elegant :). Regards, Ivan ezt =C3=ADrta (id=C5=91pont: 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 =3D 1 / value WHERE key =3D "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 =3D new DBInvertExpr(db, 1, T.DATA.VALUE); > DBCommand cmd =3D db.createCommand(); > cmd.set(T.DATA.VALUE.to(inv)); > cmd.where(T.DATA.KEY.is(23)); > - jan > > --047d7b86e992c81c74053db35e4c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,=C2=A0

another solution
DBValueExpr v =3D db.getValueExpr(1, DataType.INTEGER);
DBColumnExpr inv =3D v.divideBy(T.DATA_VALUE);
DBCommand cmd = =3D db.createCommand();=C2=A0=C2=A0
cmd.set(T.DATA.VALUE.to(inv));
cmd.wher= e(T.DATA.KEY.is(23)= );=C2=A0=C2=A0

But if you use it many t= imes, Jan's solution is better and much more elegant :).

=
Regards,
Ivan



<jan@glaubitz.org> ezt =C3=ADrta (id=C5=91pont: 2016. s= zept. 30., P, 7:27):
Hello,
=C2=A0
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":
<= br>
UPDATE data SET value =3D 1 / value WHERE key =3D "someKey";
<= br>
Any ideas how to achieve this in EmpireDB?

You can extends=C2=A0DBColumnExpr and implement the addSQL method with= something like
=C2=A0

buf.append(getObjectValue(DataType.INTEGER, this.expr1, CTX_DEFAULT, nul= l));
buf.append(" \\ ");
buf.append(getObjectValue(DataTy= pe.INTEGER, this.expr2, CTX_DEFAULT, null));

and use it like
=C2=A0

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

- jan
=C2=A0
--047d7b86e992c81c74053db35e4c--