Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    1,315

    [firebird] stored procedure con risultato differente

    firebird 2.1.3

    Ciao a tutti,
    ho questo problemuccio che mi sta mettendo a tappeto da oltre 10giorni!

    all'origine doveva essere una Stored Procedure ricorsiva, che ho ridotto ad una stored procedure che effettua 4/5 volte lo stesso tipo di ricerca.

    il problema è che non riesco ad ottenere il risultato che ''dovrei''. mi spiego:

    la stored che attinge dati da 1 sola tabella,

    se la eseguo con il debug ottengo (correttamente) un risultato di 9 righe,
    se invece la eseguo normalmente ottengo (erroneamente) un risultato di 7 righe.



    per eseguire la stored in modalità debug ho scaricato la versione free di EMS sql firebird...

    non so dove sbaglio e non so se sbaglio.... e non capisco perchè la stessa stored restituisce un dataresoult diverso.

    spero in Voi!

    grazie


    questa è la mia tabella:
    codice:
    CREATE TABLE DISTINTABASE (
        ID INTEGER NOT NULL,
        IDARTICOLO INTEGER NOT NULL,
        IDARTICOLODISTINTA INTEGER NOT NULL);

    questi i dati

    codice:
    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);

    questa la stored procedure:

    codice:
    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

  2. #2
    Ciao, secondo mè dipende dal fatto che nelle varie for select che ci sono annidate usi sempre le stesse variabili per l'into, quindi vengono sempre sovrascritte.

  3. #3
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    1,315
    grazie della tua risposta.

    l'output delle varie select deve andare per forza nelle stesse variabili.

    il problema, e' comunque sulle variabili...

    sto testando...

    http://tracker.firebirdsql.org/browse/CORE-2911

    grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.