Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: [X] Tree/Graph structure in many-to-many relationship, avoiding/detecting circularity
Here's a stored proc that traces out from a starting point and finds all
connected items without getting caught in loops.
You can add code to the 'continue' condition to trap all loop points and a
level column to the stack/list to track how far an item is from the start
(for your tree view).
CREATE PROCEDURE cmk_TraceUfid
@ufid binary(12)
AS
BEGIN
SET NOCOUNT ON
while( 1=1 )
begin
SET NOCOUNT OFF
END For C++ code to display the tree without using a stored proc you could use somethnig like :
void CkGnDlgShowConn::LoadTree( CkGnRec &R ) {
m_Tree.BeginWaitCursor();
m_Tree.DeleteAllItems();
ufids.Empty(); // list of CkGnRec put into tree AddRec(TVI_ROOT, R, depth); // depth is max depth to trace ufids.Empty();
m_Tree.SelectItem(NULL);
m_Tree.EndWaitCursor();
}
// P is parent - default = NULL
void CkGnDlgShowConn::AddRec( HTREEITEM T, CkGnRec &R, short D, CkGnRec *P )
{
...
CString s = <formated string describing R> HTREEITEM t = m_Tree.InsertItem(s, T);
...
// if found loop then stop tracing this branch and back up if( ufids.Contains(R.Ufid) ) return; ufids.Add(R.Ufid);
...
if( D < 1 ) return; // reached max allowable trace depth
...
CkGnRec *r = NULL;
<loop>
r = <Next connected item> AddRec(t, *r, D-1, &R); // recursive trace - try to minimizefunction state information
<end loop>
...
}
...cmk Received on Mon Mar 04 2002 - 13:59:18 CST
![]() |
![]() |