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

If stored procedure with execute statement with external database fails at runtime, external database remains attached. [CORE2138] #2569

Closed
firebird-automations opened this issue Oct 22, 2008 · 10 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Alexandre Moradell (amoradell)

Attachments:
execute_statement_external_database_bad.png

I tried the new feature Execute Statement with external database.

As I test, alter and run the stored procedure, I got error messages (problem with variables not recognized)

After several tries, I placed the variables correctly and execution was ok, I commit and disconnect from calling database (where the SP was created).

The external database was not opened via any other clients. And I saw that this external database was attached.

I supposed the first errors didn't detach properly the external database.

Commits: 14a9ecf

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

Do you have reproducible test case ?

@firebird-automations
Copy link
Collaborator Author

Modified by: @hvlad

assignee: Vlad Khorsun [ hvlad ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexandre Moradell (amoradell)

Yes I will post one tomorrow (23 october)

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexandre Moradell (amoradell)

-- But with this one, I get an error (see file attached) and REFERENCEDB stays attached .
SELECT z.auteur01, p.AUTEUR1 FROM AUTEURS z left join XXXRECUPAUTHOBAD(compmaj(z.auteur01)) p on (1=1)

@firebird-automations
Copy link
Collaborator Author

Modified by: Alexandre Moradell (amoradell)

Attachment: execute_statement_external_database_bad.png [ 11111 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Alexandre Moradell (amoradell)

The test case :

-- the bad one : compile is ok but variable NOMPrenom is not recognized (see file attached)

SET TERM ^ ;
create or ALTER PROCEDURE XXXRECUPAUTHOBAD (
NOMPRENOM Varchar(240) )
RETURNS (
AUTEUR1 Varchar(240) )
AS
declare xs varchar(250);
begin
xs = 'SELECT first 1 a.PPKNOMPN FROM RESP a where a.CMNOMPN = :NOMPRENOM';
FOR EXECUTE STATEMENT (:xs) (:nomprenom)
ON EXTERNAL 'localhost/3070:C:\Firebird25\examples\REFERENCEDB.fDB' AS USER 'sysdba' PASSWORD 'masterke'
WITH AUTONOMOUS TRANSACTION INTO :auteur1 DO
SUSPEND;
end^
SET TERM ; ^

GRANT EXECUTE ON PROCEDURE XXXRECUPAUTHOBAD TO SYSDBA;

-- the correct one : I declare a local variable and pass the variable
SET TERM ^ ;
CREATE OR ALTER PROCEDURE XXXRECUPAUTHO (
NOMPRENOM Varchar(240) )
RETURNS (
AUTEUR1 Varchar(240) )
AS
declare XS varchar(250);
declare XNOMPRENOM varchar(240);
begin
XS = 'SELECT first 1 a.PPKNOMPN FROM RESP a where a.CMNOMPN = :xNOMPRENOM';
FOR EXECUTE STATEMENT (:xs) (xNOMPRENOM := NOMPRENOM)
ON EXTERNAL 'localhost/3070:C:\Firebird25\examples\REFERENCEDB.fDB' AS USER 'sysdba' PASSWORD 'masterke'
WITH AUTONOMOUS TRANSACTION INTO :auteur1 DO
SUSPEND;
end^
SET TERM ; ^

GRANT EXECUTE ON PROCEDURE XXXRECUPAUTHO TO SYSDBA;

-- With this query, it's ok : I get the results (found a match or null) and when I commit, REFERENCEDB is detached.
SELECT z.auteur01, p.AUTEUR1 FROM AUTEURS z left join XXXRECUPAUTHO(compmaj(z.auteur01)) p on (1=1)

-- But with this one, I get an error (see file attached) and REFERENCEDB stays attached .
SELECT z.auteur01, p.AUTEUR1 FROM AUTEURS z left join XXXRECUPAUTHOBAD(compmaj(z.auteur01)) p on (1=1)

-- firebird.log extract
ALMO (Server) Thu Oct 23 09:18:51 2008
Shutting down the server with 1 active connection(s) to 1 database(s)

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

The bug was only if AUTONOMOUS transaction used. If statement prepare fails then its AUTONOMOUS transaction was not finished (not rolled back) and correspondingly its attachment was not released.

@firebird-automations
Copy link
Collaborator Author

Modified by: @hvlad

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

resolution: Fixed [ 1 ]

Fix Version: 2.5 Beta 1 [ 10251 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

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

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

QA Status: No test

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

2 participants