in reply to Re: Path computation for SQL generation
in thread Path computation for SQL generation

Graph::BFS (breadth-first search) looks like exactly what you need. Tables are vertices, foreign keys are edges (unfortunately, at a quick glance it does not look like you can name edges). Look at its superclass Graph::Traversal for the documentation, which is sparse even there. You'll need to create the graph using Graph::Undirected (again, look at the documentation in the superclass Graph::Base). Here's the Graph package.
  • Comment on Re: Re: Path computation for SQL generation

Replies are listed 'Best First'.
Re: Re: Re: Path computation for SQL generation
by dragonchild (Archbishop) on Jan 26, 2004 at 20:39 UTC
    I'm reading through the source (not that I understand much) for Graph. How on earth do I ask the following question:

    Is there a path from X to Y and, if there is, give me the elements I traverse.

    Update: After playing around a bunch, I found the following:

    my $SSSP = $graph->SSSP_Dijkstra($start); my %attrs = $graph->get_attributes($end); my $path = $attrs{path}; die "No path found\n" if !defined $path; print "Path: @$path\n";

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.