火鸟常数值

发布于 2024-08-13 19:40:18 字数 391 浏览 4 评论 0原文

是否可以拥有数据库范围的常量? 我想要的是定义一个常量,例如:

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

,然后在例如触发器中使用它,例如:

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;

Is it possible to have database wide constants?
What I want is to define a constant like:

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

and then use it in for example a trigger like:

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

何以笙箫默 2024-08-20 19:40:18

您可以使用生成器:

SET GENERATOR DELETE_CONSTANT TO 3;

...

EXECUTE PROCEDURE SP_ADD_HISTORY 'PRJ_PROJECT', GEN_ID(DELETE_CONSTANT, 0);

更新:是的,为此目的使用生成器是危险的,因为它们可以更改。
但是,在 FireBird 3.0 Alpha 1 中,可以使用访问权限消除此风险: 授予访问权限发电机

You could use a 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, as they can be changed.
However, in FireBird 3.0 Alpha 1 this risk can be eliminated using access rights: Grants access on generators.

蓝咒 2024-08-20 19:40:18

我认为没有一种简单的方法来声明常量。

我可以通过为用户定义的函数创建自己的 DLL,并为每个常量创建一个函数来完成。

我认为使用生成器作为“全局”常量的想法非常出色。

但是您可以创建一个“局部常量”以使代码更具可读性:

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;

I don't think there is an easy way for declaring constants.

I could be done by creating you own DLL for user defined function, and lmake a function for each constant.

I Think the Idea using generators as "global" constants is briliant.

But you can make a "local constant" to make your code a bit more readable:

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;
一绘本一梦想 2024-08-20 19:40:18

使用带有触发器的单行表来防止插入和删除。必须读取它当然不会使代码更清晰,但它有助于实现这样的“常量”。同时删除除 sysdba 之外的所有人的写入权限

Use a single row table with triggers that prevent insertion and deletion from it. Having to read from it certainly does not makes code clearer but it helps to implement such "constants". Also remove write permissions from everybody but sysdba

为你鎻心 2024-08-20 19:40:18

实现一些简单的脚本预处理器,将常量转换为值

@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;

您可以

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

You can implement some simple preprocesor of yours 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文