| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | use Modern::Perl; | ||
| 4 | use 5.010; | ||
| 5 | |||
| 6 | use autodie qw(:all); | ||
| 7 | no indirect ':fatal'; | ||
| 8 | |||
| 9 | use Carp; | ||
| 10 | use DBI; | ||
| 11 | use Graph; | ||
| 12 | use GraphViz; | ||
| 13 | |||
| 14 | use Getopt::Euclid qw( :vars<opt_> ); | ||
| 15 | use Data::Dumper; | ||
| 16 | use VSGDR::StaticData; | ||
| 17 | |||
| 18 | use version ; our $VERSION = qv('0.01'); | ||
| 19 | |||
| 20 | my %tables; | ||
| 21 | |||
| 22 | my $dbh = DBI->connect("dbi:ODBC:${opt_connection}", q{}, q{}, { AutoCommit => 1, RaiseError => 1 }); | ||
| 23 | |||
| 24 | my $ra_dep = VSGDR::StaticData::dependency($dbh); | ||
| 25 | my $g = Graph->new( 'directed' => 1 ) ; | ||
| 26 | my $g2 = GraphViz->new(); | ||
| 27 | |||
| 28 | foreach my $rec (@{$ra_dep}) { | ||
| 29 | #warn Dumper $rec; | ||
| 30 | $g->add_vertex("$$rec[1].$$rec[2]") ; | ||
| 31 | $g->add_vertex("$$rec[4].$$rec[5]") ; | ||
| 32 | $g->add_edge("$$rec[1].$$rec[2]","$$rec[4].$$rec[5]"); | ||
| 33 | |||
| 34 | $g2->add_node("$$rec[1].$$rec[2]") ; | ||
| 35 | $g2->add_node("$$rec[4].$$rec[5]") ; | ||
| 36 | $g2->add_edge("$$rec[1].$$rec[2]" => "$$rec[4].$$rec[5]",label => "$$rec[6]"); | ||
| 37 | |||
| 38 | } | ||
| 39 | |||
| 40 | open my $H, ">", "c:\\temp\\mb.jpg" ; | ||
| 41 | binmode $H; | ||
| 42 | $g2->as_jpeg($H); | ||
| 43 | close $H; | ||
| 44 | |||
| 45 | |||
| 46 | ##### remove any successors....... we're not asked to dump data for these | ||
| 47 | ####for my $v ( $g->all_successors($combinedName)) { | ||
| 48 | #### $g->delete_vertex($v); | ||
| 49 | ####} | ||
| 50 | #### | ||
| 51 | ##### remove any unconnected nodes | ||
| 52 | ####for my $v ( grep {$_ ne $combinedName } $g->vertices() ) { | ||
| 53 | #### if ( ! $g->is_reachable($combinedName,$v) && ! $g->is_reachable($v,$combinedName) ) { | ||
| 54 | #### $g->delete_vertex($v); | ||
| 55 | #### } | ||
| 56 | ####} | ||
| 57 | |||
| 58 | if ($g->has_a_cycle() ){ | ||
| 59 | warn "There are cycles in the dependencies."; | ||
| 60 | warn "Unsorted List of tables follows."; | ||
| 61 | my @res = $g->vertices(); | ||
| 62 | do { $" = "\n"; print "@res"; }; | ||
| 63 | } | ||
| 64 | else { | ||
| 65 | my @res = $g->topological_sort(); | ||
| 66 | do { $" = "\n"; print "@res"; }; | ||
| 67 | } | ||
| 68 | |||
| 69 | exit ; | ||
| 70 | |||
| 71 | END { | ||
| 72 | $dbh->disconnect() if $dbh ; | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | __DATA__ |