Subject Re: Constants
Author Adam
--- In firebird-support@yahoogroups.com, Adomas Urbanavicius
<adomas@i...> wrote:
>
> Hi,
> Is there any way to implement constants in database ?
> We are using some custom user rights in applications, which are defined
> as constants in code (C++,something like #define
> C_IALLOW_VIEW_HISTORY_OLDER1YEAR 15; or static const
> C_IALLOW_VIEW_HISTORY_OLDER1YEAR = 15, NATIONAL_CURRENCY, etc), for
> obvious reasons we dont want to hardcode number 15, "USD" in PL\SQL.
> (Now we are using configuration table, like const_name, number; I think
> about writing udf with GetConst("NAME")), but it would be much better,
> to add somewhere include of our header with constants, and then just
use
> it with : if Custom_Right <> C_IALLOW_VIEW_HISTORY_OLDER1YEAR then
....,
> or insert into orders ... NATIONAL_CURRENCY..
>
>
Hello Adomas,

We have a config table.

CREATE TABLE CONFIG
(
ID INTEGER,
NAME VARCHAR(50),
PREFERENCE BLOB SUB_TYPE 0 SEGMENT SIZE 1,
CONSTRAINT PK_CONFIG PRIMARY KEY (ID)
);

Most of our preferences are Yes / No, so choose an appropriate segment
size for your needs.

I also have a UDF that converts BLOBToInt, BLOBToChar, etc.

You can use this sort of model to create a stored procedure that
accepts either the name or the ID then returns the particular
preference. Our system goes one step further and the "constants" are
variable depending on who logs in, where they are logged in from and
other external factors.

Adding a new constant is as simple as inserting a new record into the
table.

Adam