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

stored procedure do not work correctly BUG??? [CORE2911] #3295

Closed
firebird-automations opened this issue Mar 6, 2010 · 12 comments
Closed

stored procedure do not work correctly BUG??? [CORE2911] #3295

firebird-automations opened this issue Mar 6, 2010 · 12 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: fulvio (fulvio)

Attachments:
result.jpg

Hi to all,

running my stored procedure with two parameters: idpadrein = null, idarticoloin=1

the result should be 9 rows!

the wrong result is 7 rows!

with EMS debugger the result is 9 rows, but running the stored procedure with EMS (no debugger) the result is 7 rows!

please tell me what is wrong.

thanks

this is my table

CREATE TABLE DISTINTABASE (
ID INTEGER NOT NULL,
IDARTICOLO INTEGER NOT NULL,
IDARTICOLODISTINTA INTEGER NOT NULL);

this is my data

INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (9906, 4, 3);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (6, 4, 2);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (4, 4, 1);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (9908, 1, 6);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (7, 2, 3);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (9909, 1, 7);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (12, 3, 6);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (9901, 1, 2);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (9902, 1, 3);
INSERT INTO DISTINTABASE (ID, IDARTICOLO, IDARTICOLODISTINTA) VALUES (19, 3, 5);

this is my simple stored procedure:

CREATE PROCEDURE ARTICOLIFIGLI (
idpadrein integer,
idarticoloin integer)
returns (
out_id integer,
out_idarticolopadre integer,
out_idpadre integer,
out_idarticolo integer)
as
begin
/* Procedure Text */

for select
:idpadrein,
distintabase\.idarticolo,
distintabase\.idarticolodistinta
from distintabase where
distintabase\.idarticolo=:idarticoloin
into
out\_idpadre,
out\_idarticolopadre,
out\_idarticolo
do
 begin
  if \(out\_id is null\) then out\_id=1; else out\_id=out\_id\+1;
  suspend;

    for select
    :out\_id,
    distintabase\.idarticolo,
    distintabase\.idarticolodistinta
    from distintabase where
    distintabase\.idarticolo=:out\_idarticolo
    into
    out\_idpadre,
    out\_idarticolopadre,
    out\_idarticolo
    do
     begin
      if \(out\_id is null\) then out\_id=1; else out\_id=out\_id\+1;
      suspend;

        for select
        :out\_id,
        distintabase\.idarticolo,
        distintabase\.idarticolodistinta
        from distintabase where
        distintabase\.idarticolo=:out\_idarticolo
        into
        out\_idpadre,
        out\_idarticolopadre,
        out\_idarticolo
        do
         begin
          if \(out\_id is null\) then out\_id=1; else out\_id=out\_id\+1;
          suspend;

            for select
            :out\_id,
            distintabase\.idarticolodistinta
            from distintabase where
            distintabase\.idarticolo=:out\_idarticolo
            order by distintabase\.idarticolodistinta
            into
            out\_idpadre,
            out\_idarticolo
            do
             begin
              if \(out\_id is null\) then out\_id=1; else out\_id=out\_id\+1;
              suspend;
            end
         end

     end

 end

end

@firebird-automations
Copy link
Collaborator Author

Commented by: fulvio (fulvio)

this is the image of results

@firebird-automations
Copy link
Collaborator Author

Modified by: fulvio (fulvio)

Attachment: result.jpg [ 11591 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

The behavior of using the same variable as both input and output in the same command is undefined AFAIK.

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

Correct, it's dictated by the FB internals and thus can be considered "as designed". However, AFAIU it doesn't comply with the SQL specification. So I'm not sure what is better: close this ticket as "won't fix" or just downgrade its priority and keep it open until it's fixed some day.

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

This is how it works from the day one.
I vote for closing this ticket with "won't fix" and, probably creating new feature request.

PS EMS, IBE, etc "debuggers" is just emulators, they can't work exactly same way as Firebird

@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

Modified by: @pcisar

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

@firebird-automations
Copy link
Collaborator Author

Commented by: fulvio (fulvio)

and now, how to resolve this problem?

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

Don't use the same variable as both input and output in the same command

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

temp_idarticolo = out_idarticolo;

for select
:out_id,
distintabase.idarticolo,
distintabase.idarticolodistinta
from distintabase where
distintabase.idarticolo=:temp_idarticolo
into
:out_idpadre,
:out_idarticolopadre,
:out_idarticolo

@firebird-automations
Copy link
Collaborator Author

Commented by: fulvio (fulvio)

hi,

I've insert a tmp variable
I Don't use the same variable as both input and output in the same command

the result is always the same....

can you tell me whot is wrong?
can you help me?

thanks

CREATE PROCEDURE ARTICOLIFIGLI (
idarticoloin integer)
returns (
out_idarticolopadre integer,
out_idarticolo integer)
as
declare variable temp_idarticolo integer;
begin
/* Procedure Text */

for select
distintabase\.idarticolo,
distintabase\.idarticolodistinta
from distintabase where
distintabase\.idarticolo=:idarticoloin
into
out\_idarticolopadre,
out\_idarticolo
do
 begin
  temp\_idarticolo = out\_idarticolo;
  suspend;

    for select
    distintabase\.idarticolo,
    distintabase\.idarticolodistinta
    from distintabase where
    distintabase\.idarticolo=:temp\_idarticolo
    into
    out\_idarticolopadre,
    out\_idarticolo
    do
     begin
      temp\_idarticolo = out\_idarticolo;
      suspend;

        for select
        distintabase\.idarticolo,
        distintabase\.idarticolodistinta
        from distintabase where
        distintabase\.idarticolo=:temp\_idarticolo
        into
        out\_idarticolopadre,
        out\_idarticolo
        do
         begin
          temp\_idarticolo = out\_idarticolo;
          suspend;

            for select
            distintabase\.idarticolo,
            distintabase\.idarticolodistinta
            from distintabase where
            distintabase\.idarticolo=:temp\_idarticolo
            order by distintabase\.idarticolodistinta
            into
            out\_idarticolopadre,
            out\_idarticolo
            do
             begin
              suspend;
            end
         end

     end

 end

end

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

You used same variable in different nesting commands. When evaluating the outer ones, the variable will have changed and will be compared with something you assigned in the inner loops.

Please move this to support list, as the tracker is not for this.

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