db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John English <john.fore...@gmail.com>
Subject Re: Unique constraints and nulls
Date Thu, 15 May 2014 09:10:23 GMT
On 14/05/2014 17:35, John English wrote:
>    delete from Foo where A=? and B=?
>
> However, when the value for B is null, nothing gets deleted (presumably due to
> the query containing B=NULL rather than B IS NULL).

I now have this, which works (but is rather ugly)... I'd be grateful if anyone 
can tell me a more elegant way to do it:

	try (Transaction t = db.startTransaction()) {
           if (b == null) {
             db.update("delete from Foo where A=? and B is null", a);
           }
           else {
             db.update("delete from Foo where A=? and B=?", a, b);
           }
           update("insert into Foo values(?,?)", a, b);
           t.commit();
         }

-- 
John English

Mime
View raw message