Snippet führt zu einer unendlich geführten Schleife an dieser UnterroutineMySql

MySQL DBMS-Forum
Anonymous
 Snippet führt zu einer unendlich geführten Schleife an dieser Unterroutine

Post by Anonymous »

Dies ist ein Code -Snippet zur Unterscheidungssprache, das SQL ähnelt. Könnten Sie sich diesen Ausschnitt ansehen und alle schlechten Konstruktionen entdecken? Im Moment wird diese Unterroutine auf eine andere Unterroutine aufgerufen und schleift weiter. < /P>

Code: Select all

subroutine(get_path(alt_sel_cat_id = f8) = vc)
declare fldr_cnt = i4 with protect, constant(size(fav_fldr->fldr, 5))
declare pos1 = i4 with protect, noconstant(0)
declare idx = i4 with protect, noconstant(0)

declare folder_id = f8 with protect, noconstant(0)
declare parent_id = f8 with protect, noconstant(0)
declare is_root = i2 with protect, noconstant(0)
declare path = vc with protect, noconstant("")

set folder_id = alt_sel_cat_id
set parent_id = fav_fldr->fldr[LOCATEVAL(pos1, 1, fldr_cnt, folder_id, fav_fldr->fldr[pos1].folder_id)].parent_folder_id
set is_root = EVALUATE2(IF(parent_id = 0) 1 ELSE 0 ENDIF)
set path = fav_fldr->fldr[LOCATEVAL(pos1, 1, fldr_cnt, folder_id, fav_fldr->fldr[pos1].folder_id)].folder

while (is_root = 0) ;not the parent folder
if (parent_id = 0)
set is_root = 1 ;reached the parent, time to stop
else
;find the index of the parent folder
set pos1 = LOCATEVAL(idx, 1, fldr_cnt, parent_id, fav_fldr->fldr[idx].folder_id)
if (pos1 > 0) ;we located the parent folder in the record
set path = BUILD2(fav_fldr->fldr[pos1].folder, "/", path)
set parent_id = fav_fldr->fldr[pos1].parent_folder_id ;update parent_id to the parent's parent folder_id
endif
endif
endwhile

return (path)`enter code here`
end ;get_path

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post