Firebird Constant

Is it possible to have wide databases? I want to define a constant like:

  • UPDATE_CONSTANT = 1
  • INSERT_CONSTANT = 2
  • DELETE_CONSTANT = 3

and then use it, for example, to run, for example:

CREATE TRIGGER AD_PRJ_PROJECTS FOR PRJ_PROJECT ACTIVE AFTER DELETE POSITION 1 AS BEGIN EXECUTE PROCEDURE SP_ADD_HISTORY 'PRJ_PROJECT', DELETE_CONSTANT; END; 
+4
source share
4 answers

You can use the generator:

 SET GENERATOR DELETE_CONSTANT TO 3; ... EXECUTE PROCEDURE SP_ADD_HISTORY 'PRJ_PROJECT', GEN_ID(DELETE_CONSTANT, 0); 

Update : yes, using a generator for this purpose is dangerous because they can be changed. However, in FireBird 3.0 Alpha 1, this risk can be eliminated with the help of access rights: Provides access to generators .

+2
source

I don't think there is an easy way to declare constants.

I could do this by creating my own DLL for a user-defined function, and an lmake function for each constant.

I think the idea of โ€‹โ€‹using generators as "global" constants is more attractive.

But you can make a "local constant" to make the code more understandable:

 CREATE TRIGGER AD_PRJ_PROJECTS FOR PRJ_PROJECT ACTIVE AFTER DELETE POSITION 1 AS DECLARE VARIABLE DELETE_CONSTANT INTEGER; BEGIN DELETE_CONSTANT = 1; EXECUTE PROCEDURE SP_ADD_HISTORY 'PRJ_PROJECT', DELETE_CONSTANT; END; 
+2
source

You can implement some simple preprocessor of your scripts that converts constants to values.

triggers.presql

 @DELETE_CONSTANT = 1 CREATE TRIGGER AD_PRJ_PROJECTS FOR PRJ_PROJECT ACTIVE AFTER DELETE POSITION 1 BEGIN EXECUTE PROCEDURE SP_ADD_HISTORY 'PRJ_PROJECT', DELETE_CONSTANT; END; 

triggers.sql

 CREATE TRIGGER AD_PRJ_PROJECTS FOR PRJ_PROJECT ACTIVE AFTER DELETE POSITION 1 BEGIN EXECUTE PROCEDURE SP_ADD_HISTORY 'PRJ_PROJECT', 1; END; 
0
source

Use a single row table with triggers that prevent insertion and deletion from it. The need to read from it, of course, does not make the code more understandable, but it helps to implement such "constants". Also remove write permissions from everyone but sysdba

0
source

All Articles