![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I am writing an application that requires a multi-level tree structure. I'm storing the data in a table of the form ID Description ParentId For speed, I would like to write a couple of Stored procedures that can run up and down the tree structure, but at the moment, I have somthing like this: CREATE PROCEDURE GetParentUnit_A(INOUT :Pid VARCHAR(10), IN :lvl INTEGER) AS begin print :lvl; declare :i VARCHAR(10); declare zz CURSOR FOR SELECT parentId from Units WHERE unitId = :Pid; OPEN zz; Fetch next from zz into :Pid; if :Pid = 'Root' then set :Pid = :Pid; else set :lvl = :lvl + 1; Call GetParentUnit_B(:Pid,:lvl); end if; CLOSE zz; end; GetParentUnit_B is idential to the above except it calls GetParentUnit_A just before the CLOSE zz. My problem is that when I run this, I get 'Multiple Cursor Definition zz' My question is, is there a way of making the CURSOR zz local to this PROCEDURE, so that when GetParentUnit_B tries to declare one, it makes ITS own local version. If you were thinking of calling the cursor somthing else in GetParentUnit_B, this won't help much as objects deeper than 2 levels down the tree will still cause one or other of these procedures to be called more than once. Bottom line is: Is there any way of accomplishing recursive Procedure calls in Pervasive, or am I wasting my time trying to get it to work? Thanks, ChrisM. -- Please remove shoes to reply But what ... is it good for? - Engineer at the Advanced Computing Systems Division of IBM, 1968, commenting on the microchip. |
#3
| |||
| |||
|
|
I've tested recursion before in the database, and found that the engine used to fail after about 120 levels, but that it crashed miserably. (Probably a stack failure.) I believe they changed it to allow only 32 levels (pretty standard in the SQL industry, or so I'm told) now. However, I did not test with cursors in my tests. I would think that this should be logged as a formal incident with Pervasive to get the best (i.e. quickest) results. I'll try some of my own tests, though, in the meantime... Goldstar Software Inc. Building on Btrieve(R) for the Future(SM) Bill Bach BillBach (AT) goldstarsoftware (DOT) com http://www.goldstarsoftware.com *** Pervasive.SQL Service & Support Classes *** Chicago: August, 2004: See our web site for details! ChrisM wrote: Hi, I am writing an application that requires a multi-level tree structure. I'm storing the data in a table of the form ID Description ParentId For speed, I would like to write a couple of Stored procedures that can run up and down the tree structure, but at the moment, I have somthing like this: CREATE PROCEDURE GetParentUnit_A(INOUT :Pid VARCHAR(10), IN :lvl INTEGER) AS begin print :lvl; declare :i VARCHAR(10); declare zz CURSOR FOR SELECT parentId from Units WHERE unitId = :Pid; OPEN zz; Fetch next from zz into :Pid; if :Pid = 'Root' then set :Pid = :Pid; else set :lvl = :lvl + 1; Call GetParentUnit_B(:Pid,:lvl); end if; CLOSE zz; end; GetParentUnit_B is idential to the above except it calls GetParentUnit_A just before the CLOSE zz. My problem is that when I run this, I get 'Multiple Cursor Definition zz' My question is, is there a way of making the CURSOR zz local to this PROCEDURE, so that when GetParentUnit_B tries to declare one, it makes ITS own local version. If you were thinking of calling the cursor somthing else in GetParentUnit_B, this won't help much as objects deeper than 2 levels down the tree will still cause one or other of these procedures to be called more than once. Bottom line is: Is there any way of accomplishing recursive Procedure calls in Pervasive, or am I wasting my time trying to get it to work? Thanks, ChrisM. -- Please remove shoes to reply But what ... is it good for? - Engineer at the Advanced Computing Systems Division of IBM, 1968, commenting on the microchip. |
#4
| |||
| |||
|
|
Hi Bill, Thanks for your reply. 32 Levels of recursion will be more than enough. The normal depth of the tree is about 3-4 levels... Do you have any simple examples of your recursive code that you would be prepared to share? I'm prettu new to Pervasive and to some extent Stored Procedure writing and would appreciate any help I can get. Cheers, Chris. -- Please remove shoes to reply But what ... is it good for? - Engineer at the Advanced Computing Systems Division of IBM, 1968, commenting on the microchip. "Bill Bach" <bbach (AT) cncdsl (DOT) com> wrote in message news:412952CC.ED7368B5 (AT) cncdsl (DOT) com... I've tested recursion before in the database, and found that the engine used to fail after about 120 levels, but that it crashed miserably. (Probably a stack failure.) I believe they changed it to allow only 32 levels (pretty standard in the SQL industry, or so I'm told) now. However, I did not test with cursors in my tests. I would think that this should be logged as a formal incident with Pervasive to get the best (i.e. quickest) results. I'll try some of my own tests, though, in the meantime... Goldstar Software Inc. Building on Btrieve(R) for the Future(SM) Bill Bach BillBach (AT) goldstarsoftware (DOT) com http://www.goldstarsoftware.com *** Pervasive.SQL Service & Support Classes *** Chicago: August, 2004: See our web site for details! ChrisM wrote: Hi, I am writing an application that requires a multi-level tree structure. I'm storing the data in a table of the form ID Description ParentId For speed, I would like to write a couple of Stored procedures that can run up and down the tree structure, but at the moment, I have somthing like this: CREATE PROCEDURE GetParentUnit_A(INOUT :Pid VARCHAR(10), IN :lvl INTEGER) AS begin print :lvl; declare :i VARCHAR(10); declare zz CURSOR FOR SELECT parentId from Units WHERE unitId = :Pid; OPEN zz; Fetch next from zz into :Pid; if :Pid = 'Root' then set :Pid = :Pid; else set :lvl = :lvl + 1; Call GetParentUnit_B(:Pid,:lvl); end if; CLOSE zz; end; GetParentUnit_B is idential to the above except it calls GetParentUnit_A just before the CLOSE zz. My problem is that when I run this, I get 'Multiple Cursor Definition zz' My question is, is there a way of making the CURSOR zz local to this PROCEDURE, so that when GetParentUnit_B tries to declare one, it makes ITS own local version. If you were thinking of calling the cursor somthing else in GetParentUnit_B, this won't help much as objects deeper than 2 levels down the tree will still cause one or other of these procedures to be called more than once. Bottom line is: Is there any way of accomplishing recursive Procedure calls in Pervasive, or am I wasting my time trying to get it to work? Thanks, ChrisM. -- Please remove shoes to reply But what ... is it good for? - Engineer at the Advanced Computing Systems Division of IBM, 1968, commenting on the microchip. |
#5
| |||
| |||
|
|
Hi, I am writing an application that requires a multi-level tree structure. I'm storing the data in a table of the form ID Description ParentId For speed, I would like to write a couple of Stored procedures that can run up and down the tree structure, but at the moment, I have somthing like this: CREATE PROCEDURE GetParentUnit_A(INOUT :Pid VARCHAR(10), IN :lvl INTEGER) AS begin print :lvl; declare :i VARCHAR(10); declare zz CURSOR FOR SELECT parentId from Units WHERE unitId = :Pid; OPEN zz; Fetch next from zz into :Pid; if :Pid = 'Root' then set :Pid = :Pid; else set :lvl = :lvl + 1; Call GetParentUnit_B(:Pid,:lvl); end if; CLOSE zz; end; GetParentUnit_B is idential to the above except it calls GetParentUnit_A just before the CLOSE zz. My problem is that when I run this, I get 'Multiple Cursor Definition zz' My question is, is there a way of making the CURSOR zz local to this PROCEDURE, so that when GetParentUnit_B tries to declare one, it makes ITS own local version. If you were thinking of calling the cursor somthing else in GetParentUnit_B, this won't help much as objects deeper than 2 levels down the tree will still cause one or other of these procedures to be called more than once. Bottom line is: Is there any way of accomplishing recursive Procedure calls in Pervasive, or am I wasting my time trying to get it to work? Thanks, ChrisM. -- Please remove shoes to reply But what ... is it good for? - Engineer at the Advanced Computing Systems Division of IBM, 1968, commenting on the microchip. |
#6
| |||
| |||
|
|
Hi, I am writing an application that requires a multi-level tree structure. I'm storing the data in a table of the form ID Description ParentId For speed, I would like to write a couple of Stored procedures that can run up and down the tree structure, but at the moment, I have somthing like this: CREATE PROCEDURE GetParentUnit_A(INOUT :Pid VARCHAR(10), IN :lvl INTEGER) AS begin print :lvl; declare :i VARCHAR(10); declare zz CURSOR FOR SELECT parentId from Units WHERE unitId = :Pid; OPEN zz; Fetch next from zz into :Pid; if :Pid = 'Root' then set :Pid = :Pid; else set :lvl = :lvl + 1; Call GetParentUnit_B(:Pid,:lvl); end if; CLOSE zz; end; GetParentUnit_B is idential to the above except it calls GetParentUnit_A just before the CLOSE zz. My problem is that when I run this, I get 'Multiple Cursor Definition zz' My question is, is there a way of making the CURSOR zz local to this PROCEDURE, so that when GetParentUnit_B tries to declare one, it makes ITS own local version. If you were thinking of calling the cursor somthing else in GetParentUnit_B, this won't help much as objects deeper than 2 levels down the tree will still cause one or other of these procedures to be called more than once. Bottom line is: Is there any way of accomplishing recursive Procedure calls in Pervasive, or am I wasting my time trying to get it to work? Thanks, ChrisM. -- Please remove shoes to reply But what ... is it good for? - Engineer at the Advanced Computing Systems Division of IBM, 1968, commenting on the microchip. |
![]() |
| Thread Tools | |
| Display Modes | |
| |