db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Hillegas <Richard.Hille...@Sun.COM>
Subject Re: how to raise/throw an exception
Date Fri, 26 Feb 2010 13:41:47 GMT
Hi Gabriele,

One way to solve this problem would be to have your trigger call a 
database procedure, passing in whatever parameters you need from the 
triggering row. The procedure would run the sanity check query and raise 
an exception if the sanity check failed.

Hope this helps,

Gabriele Kahlout wrote:
> Hello,
> I'm porting my application from SQLite to Java DB, but don't know how
> to enforce an assertion, achieved in SQLite by:
> st.execute("CREATE TRIGGER _fk_meanings_update_1 BEFORE UPDATE ON " +
> batTable.getName()  + " FOR EACH ROW BEGIN SELECT RAISE(FAIL, 'error')
> WHERE (EXISTS (SELECT COUNT(*) FROM " + batTable.getName() + " GROUP
> BY " + lastPubColumn.getName() + " HAVING COUNT(*)>"+maxPub+"));
> END;");
> However the constraint couldn't be added as a table constraint, and
> I'm not finding how to raise an exception with Java DB, although it's
> described here:
> http://developers.sun.com/docs/javadb/
> One way was to set the identity column to null, but that was not
> allowed at compile time too. I guess I'd have to use some dirty way.

View raw message