Subject Definig variable as a domain
Author Randall Sell
Hi, I am getting an error and scratching my head as to why. Perhaps someone can clarify if this is a known FB bug, or my lack of understanding... Using FB 2.1.3

I've defined the following domain:

CREATE DOMAIN PERCENTAGE
AS Double precision
CHECK ((value is null) or ((value >= 0) and (value <= 100)))
;

And I have this procedure:

SET TERM ^ ;
ALTER PROCEDURE P_TAX_AMOUNT (
AMOUNT MONEY,
TAXRATEID FOREIGNKEY )
RETURNS (
TAXAMOUNT MONEY )
AS
DECLARE VARIABLE RATE PERCENTAGE;
BEGIN
/* given an amount and a tax rate id, calculates the tax amount */
SELECT RATE FROM V_TAXRATE
WHERE TAXRATEID = :TAXRATEID
INTO :RATE;

IF (RATE IS NULL) THEN
TAXAMOUNT = 0;
TAXAMOUNT = (CAST(RATE AS DOUBLE PRECISION) / 100) * CAST(AMOUNT AS DOUBLE PRECISION);
SUSPEND;
END^
SET TERM ; ^

Note that the local variable RATE is defined as my PERCENTAGE domain.

If I call this procedure directly with test values, it works correctly. But If I refer to this procedure via a computed column, I get an error:

Exception: validation error for variable RATE, value "10.00000000000000" At procedure 'P_TAX_AMOUNT' line: 11, col: 3

Here's a snippet of the table definition that is using this procedure:

ALTER TABLE BUDGETENTRY ADD TAXAMOUNT COMPUTED BY ((SELECT TAXAMOUNT FROM P_TAX_AMOUNT(TOTALVALUE_EXTAX, TAXRATEID)));

If I change my variable to be defined as follows:
DECLARE VARIABLE RATE Double Precision;

then everything works fine. Why? Is it because FB is pre-empting that I might be trying to store something to a variable that maybe it cannot hold? (eg the query may extract a value > 100) But sure FB doesn't do that, right? I can understand if it complained when I did try and stuff in a value not with the domain's check constraints. but 10.0000000 certainly falls between 0 and 100.

So what am I missing?

cheers,
-randall sell





[Non-text portions of this message have been removed]