Hi,
This is my first post to this list.
I've just written my first script using SQL::Translator, and I'm
impressed with the possibility of reverse-engineering SQL schemas to
generate code using it.
This was my first test (pretty much based on the documentation):
#!/usr/bin/perl
use strict;
use warnings;
use SQL::Translator;
use SQL::Translator::Parser::MySQL;
my $sql = do { local $/; <>; };
my $t = SQL::Translator->new;
SQL::Translator::Parser::MySQL::parse( $t, $sql );
my $schema = $t->schema;
my @tables = $schema->get_tables;
foreach my $t (@tables) {
print "$t\n";
my $table = $schema->get_table($t);
my @fields = $table->get_fields;
my @fk = $table->fkey_fields;
my %fk;
@[EMAIL PROTECTED] = (1) x @fk;
foreach (@fields) {
print "- $_", $fk{$_} ? " (fk)" : "", "\n";
}
}
The next step would be to do a reverse list of foreign keys -- a list
of tables that link to a given one.
Of course I could iterate through all tables and fields, but I was
wondering if there was a shortcut to that -- something like a
"get_tables_that_link_to($t)" method?
Thank you in advance,
Nelson
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
--
sqlfairy-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlfairy-developers