Subject Re: [Firebird-Java] are FB exceptions expensive?
Author Roman Rokytskyy
Hi,

> I am about the increase an int entry which is not allowed to get greater
> than MAX_VALUE. Which approach would serve better in this case?
>
> 1) trigger to check the old and new value and if the :OLD + :NEW>
> MAX_VALUE then throws an FB exception.
>
> 2) select (first query) the current value, perform add and check if the
> sum is not greater than X. If not then perform an update (second query).
>
> 3) directly perform an update like this:
>
> "update<table> set<column_name> =<column_name> + value where<pk>=?
> and (<column_name> + value)<= MAX_VALUE" and then check if affected
> rows = 1 or 0.
>
> in this case I should also provide value for MAX_VALUE.

I guess that options 1) and 3) are pretty equal in terms of network
communication, I am not sure whether 1) would produce garbage in the
database in case of exception. If no, then 1) and 3) are pretty
equivalent, 1) is more flexible, since you can change the constraints
without changing the application. The option 2) requires two roundtrips,
which is the slowest of the all options.

Roman