HSQL触发器:用户缺少特权或找不到对象:NEWROW.ID

时间:2018-11-29 09:51:08

标签: scala triggers hsqldb

我试图在更新后在hsql中实现触发器 我有一个称为组件表的表,并且在该表中进行更新时,我想使用插入触发器之后将其记录到另一个表中,为此我正在

CREATE TABLE IF NOT EXISTS "component"(
   "id" INTEGER IDENTITY,
   "name" VARCHAR(100),
   "configuration" LONGVARCHAR,
   "owner_id" INTEGER   );

CREATE TABLE IF NOT EXISTS "component_audit"(
   "id" INTEGER IDENTITY,
   "component_id" INTEGER ,
   "action" VARCHAR(20),
   "activity_time" BIGINT,
   "user_id" INTEGER,
   FOREIGN KEY ("component_id") REFERENCES "component"("id") ON UPDATE RESTRICT ON DELETE CASCADE
);

    CREATE TRIGGER trig AFTER INSERT ON "component"
       REFERENCING NEW ROW AS newrow
       FOR EACH ROW
       INSERT INTO "component_audit" ("id","component_id","action","activity_time","user_id")
       VALUES (DEFAULT, 1, newrow.id, 123, 1);

在运行HSQL时引发错误

  

由以下原因引起:org.hsqldb.HsqlException:用户缺少特权或对象   找不到:NEWROW.ID

这是因为我的id列在“ id”中,因为我需要使用小写字母(DEFAULT HSQLDB为大写) 如何通过变量替换?

1 个答案:

答案 0 :(得分:1)

只需使用与CREATE TABLE语句相同的命名即可。

CREATE TRIGGER trig AFTER INSERT ON "component"
   REFERENCING NEW ROW AS newrow
   FOR EACH ROW
   INSERT INTO "component_audit" ("id","component_id","action","activity_time","user_id")
   VALUES (DEFAULT, 1, newrow."id", 123, 1);