Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The stored procedure can not inactive Trigger [CORE4023] #4353

Closed
firebird-automations opened this issue Dec 29, 2012 · 9 comments
Closed

The stored procedure can not inactive Trigger [CORE4023] #4353

firebird-automations opened this issue Dec 29, 2012 · 9 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: KAOUANE (kaouane)

I have trigger MDF_VEHICULE active on after update table;
I have a stored procedure who update this table but I want to diactive trigger inside this procedure and activate it at last.
In core of SP I write :

EXECUTE STATEMENT 'ALTER TRIGGER MDF_VEHICULE INACTIVE';
UPDATE VEHICULE SET VALIDE = 1;
....
EXECUTE STATEMENT 'ALTER TRIGGER MDF_VEHICULE ACTIVE';

When I execute SP, I find that trigger are not inactive.

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

It's not going to work because every DDL (including activating/disactivating indices) is actually executed on commit, so you cannot do it in the middle of transaction. That said, I suppose you could workaround that using an autonomous transaction.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: KAOUANE (kaouane)

Thank you very much;
But Why the Commit statement not work in SP like Trigger?
In trigger body, I can commit transaction like :
Insert into Vehicule (...) value (....);
Commit;
Select * from vehicule;
I think that is good thing if we can commit transaction inside PS.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

Commit is not allowed in triggers either.

@firebird-automations
Copy link
Collaborator Author

Commented by: KAOUANE (kaouane)

Yes it is, thank you very much.

@firebird-automations
Copy link
Collaborator Author

Commented by: KAOUANE (kaouane)

I have found very good solution for this problem.
I define a context variable in usersession namespace called 'PROCEDURE' and at begin of trigger I put :

IF (rdb$get_context(''USER_SESSION'', ''PROCEDURE'')=1) THEN EXIT;

And at Begin of SP I put :

RDB$SET_CONTEXT(''USER_SESSION'',''PROCEDURE'',1);

and at last I put :

RDB$SET_CONTEXT(''USER_SESSION'',''PROCEDURE'',0);

This way permet to execute SP without execution of trigger specialy for currentuser.

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

I believe it's better to use USER_TRANSACTION instead of USER_SESSION in your case.

@firebird-automations
Copy link
Collaborator Author

Commented by: KAOUANE (kaouane)

I believe it's same because the value of 'procedure' are value 1 just in SP transaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant