firebird 将触发器更改为存储过程
firebird alter trigger into stored procedure
如何将触发器更改为存储过程?我有以下代码:
CREATE PROCEDURE PESTADOTRIGGER (
disparador varchar(40),
estado integer)
as
declare variable cadena varchar(500);
begin
if (:estado = 1) then
begin
cadena = 'ALTER TRIGGER ' || :disparador || ' ACTIVE';
EXECUTE STATEMENT :CADENA WITH AUTONOMOUS TRANSACTION;
END
ELSE
begin
cadena = 'ALTER TRIGGER ' || :disparador || ' INACTIVE';
EXECUTE STATEMENT :CADENA WITH AUTONOMOUS TRANSACTION;
END
end
执行存储过程时显示消息:
unsuccessful metadata update modify trigger failed no peermission for
control acess to table
我是运行用SYSDBA用户的程序,但是不行
您应该检查您的数据库用户。触发器可以由创建者、SYSDBA 用户和其他具有超级用户权限的用户更改。
尝试以 SYSDBA 用户身份执行存储过程。
编辑
这是我的测试数据库。
/******************************************************************************/
/**** Generated by IBExpert 2015.9.28.1 08.10.2015 19:06:46 ****/
/******************************************************************************/
SET SQL DIALECT 3;
SET NAMES UTF8;
CREATE DATABASE '127.0.0.1:C:\DB\Test.FDB'
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 16384
DEFAULT CHARACTER SET UTF8 COLLATION UTF8;
/******************************************************************************/
/**** Generators ****/
/******************************************************************************/
CREATE GENERATOR GEN_TEST_ID;
SET GENERATOR GEN_TEST_ID TO 0;
/******************************************************************************/
/**** Stored procedures ****/
/******************************************************************************/
SET TERM ^ ;
CREATE PROCEDURE PESTADOTRIGGER (
DISPARADOR VARCHAR(40),
ESTADO INTEGER)
AS
BEGIN
EXIT;
END^
SET TERM ; ^
/******************************************************************************/
/**** Tables ****/
/******************************************************************************/
CREATE TABLE TEST (
ID BIGINT NOT NULL,
TXT VARCHAR(50)
);
/******************************************************************************/
/**** Primary keys ****/
/******************************************************************************/
ALTER TABLE TEST ADD PRIMARY KEY (ID);
/******************************************************************************/
/**** Triggers ****/
/******************************************************************************/
SET TERM ^ ;
/******************************************************************************/
/**** Triggers for tables ****/
/******************************************************************************/
/* Trigger: TEST_BI */
CREATE TRIGGER TEST_BI FOR TEST
ACTIVE BEFORE INSERT POSITION 0
as
begin
if (new.ID is null) then
new.ID = gen_id(GEN_TEST_ID,1);
end
^
/* Trigger: TEST_TRIGGER */
CREATE TRIGGER TEST_TRIGGER FOR TEST
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.TXT='ABC') then
begin
new.TXT='CBA';
end
end
^
SET TERM ; ^
/******************************************************************************/
/**** Stored procedures ****/
/******************************************************************************/
SET TERM ^ ;
ALTER PROCEDURE PESTADOTRIGGER (
DISPARADOR VARCHAR(40),
ESTADO INTEGER)
AS
declare variable cadena varchar(500);
begin
if (:estado = 1) then
begin
cadena = 'ALTER TRIGGER ' || :disparador || ' ACTIVE';
EXECUTE STATEMENT :CADENA WITH AUTONOMOUS TRANSACTION;
END
ELSE
begin
cadena = 'ALTER TRIGGER ' || :disparador || ' INACTIVE';
EXECUTE STATEMENT :CADENA WITH AUTONOMOUS TRANSACTION;
END
end^
SET TERM ; ^
如何将触发器更改为存储过程?我有以下代码:
CREATE PROCEDURE PESTADOTRIGGER (
disparador varchar(40),
estado integer)
as
declare variable cadena varchar(500);
begin
if (:estado = 1) then
begin
cadena = 'ALTER TRIGGER ' || :disparador || ' ACTIVE';
EXECUTE STATEMENT :CADENA WITH AUTONOMOUS TRANSACTION;
END
ELSE
begin
cadena = 'ALTER TRIGGER ' || :disparador || ' INACTIVE';
EXECUTE STATEMENT :CADENA WITH AUTONOMOUS TRANSACTION;
END
end
执行存储过程时显示消息:
unsuccessful metadata update modify trigger failed no peermission for control acess to table
我是运行用SYSDBA用户的程序,但是不行
您应该检查您的数据库用户。触发器可以由创建者、SYSDBA 用户和其他具有超级用户权限的用户更改。
尝试以 SYSDBA 用户身份执行存储过程。
编辑
这是我的测试数据库。
/******************************************************************************/
/**** Generated by IBExpert 2015.9.28.1 08.10.2015 19:06:46 ****/
/******************************************************************************/
SET SQL DIALECT 3;
SET NAMES UTF8;
CREATE DATABASE '127.0.0.1:C:\DB\Test.FDB'
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 16384
DEFAULT CHARACTER SET UTF8 COLLATION UTF8;
/******************************************************************************/
/**** Generators ****/
/******************************************************************************/
CREATE GENERATOR GEN_TEST_ID;
SET GENERATOR GEN_TEST_ID TO 0;
/******************************************************************************/
/**** Stored procedures ****/
/******************************************************************************/
SET TERM ^ ;
CREATE PROCEDURE PESTADOTRIGGER (
DISPARADOR VARCHAR(40),
ESTADO INTEGER)
AS
BEGIN
EXIT;
END^
SET TERM ; ^
/******************************************************************************/
/**** Tables ****/
/******************************************************************************/
CREATE TABLE TEST (
ID BIGINT NOT NULL,
TXT VARCHAR(50)
);
/******************************************************************************/
/**** Primary keys ****/
/******************************************************************************/
ALTER TABLE TEST ADD PRIMARY KEY (ID);
/******************************************************************************/
/**** Triggers ****/
/******************************************************************************/
SET TERM ^ ;
/******************************************************************************/
/**** Triggers for tables ****/
/******************************************************************************/
/* Trigger: TEST_BI */
CREATE TRIGGER TEST_BI FOR TEST
ACTIVE BEFORE INSERT POSITION 0
as
begin
if (new.ID is null) then
new.ID = gen_id(GEN_TEST_ID,1);
end
^
/* Trigger: TEST_TRIGGER */
CREATE TRIGGER TEST_TRIGGER FOR TEST
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.TXT='ABC') then
begin
new.TXT='CBA';
end
end
^
SET TERM ; ^
/******************************************************************************/
/**** Stored procedures ****/
/******************************************************************************/
SET TERM ^ ;
ALTER PROCEDURE PESTADOTRIGGER (
DISPARADOR VARCHAR(40),
ESTADO INTEGER)
AS
declare variable cadena varchar(500);
begin
if (:estado = 1) then
begin
cadena = 'ALTER TRIGGER ' || :disparador || ' ACTIVE';
EXECUTE STATEMENT :CADENA WITH AUTONOMOUS TRANSACTION;
END
ELSE
begin
cadena = 'ALTER TRIGGER ' || :disparador || ' INACTIVE';
EXECUTE STATEMENT :CADENA WITH AUTONOMOUS TRANSACTION;
END
end^
SET TERM ; ^