Autodia
view release on metacpan or search on metacpan
version 2.03 27/04/2006
- basic Class::DBI support in perl handler
- updated Umbrello
- updated PHP to handle PHP 5
- perl parsing improvments
- improvements to Diagram.pm in Dia / Umbrello to filter non-xml-safe stuff, and use Kind field in Dia
version 2.02 09/05/2005
- no_deps is now deprecated : use -K instead
- improvements to DBI handler
- now guesses foreign keys a bit better
- added support for datatypes
- new option -k to skip superclasses
- new option -K to skip dependancies
- improvements and fixes to SQL Handler
- now supports current (4.1.x) MySQL dumps
- now supports SQL Server SQL Dumps (when stripped of non-ascii crap)
- foreign key support improved
- datatypes improved
- umbrello output fixed
- minor fix to C++ Handling in Dia and Umbrello
lib/Autodia/Diagram.pm view on Meta::CPAN
# some perl modules such as CGI.pm do things by redeclaring packages - eek!
# this is a nasty hack to get around that nasty hack. ie class is not added
# to diagram and so everything is discarded until next new package declared
if (defined $self->{"packages"}{"class"}{$class->Name})
{
print STDERR "Diagram.pm : add_class : ignoring duplicate class",
$class->Name, "\n";
# warn Dumper (original_class=>$self->{"packages"}{"class"}{$class->Name});
return $self->{"packages"}{"class"}{$class->Name};
}
# note : when running benchmark.pl this seems to appear which I guess is a
# scoping issue when calling autodial multiple times - odd, beware if using
# mod_perl or something similar, not that it breaks anything but you never know
$class->Set_Id($self->_object_count);
$self->_package_add($class);
return $class;
}
sub remove_duplicates
lib/Autodia/Handler/DBI.pm view on Meta::CPAN
warn "got key columns for table $esc_table : @key_columns\n";
if (@key_columns) {
push (@{$primary_key->{Params}}, map ({ Name=>$_, Type=>''}, @key_columns));
$Class->add_operation($primary_key);
}
# FIXME : need to subclass db's that don't work
# try using DBD, then use subclass to do horrid hacks
my $guess_foreign_keys = 1;
# get foreign keys
$sth = $dbh->foreign_key_info( $schema || undef, $dbname, '', $schema || undef, $dbname, $esc_table );
if ($sth) {
my %rels;
my $i = 1; # for unnamed rels, which hopefully have only 1 column ...
while(my $raw_rel = $sth->fetchrow_arrayref) {
$guess_foreign_keys = 0 if ($guess_foreign_keys);
warn "got relation $raw_rel\n";
my $pk_tbl = $raw_rel->[2];
my $pk_col = lc $raw_rel->[3];
my $fk_col = lc $raw_rel->[7];
my $relid = ($raw_rel->[11] || ( "__dcsld__" . $i++ ));
$rels{$relid}->{tbl} = $pk_tbl;
$rels{$relid}->{cols}->{$pk_col} = $fk_col;
push(@{$self->{foreign_tables}{$pk_tbl}}, {field => $pk_col, table => $esc_table, class => $Class });
$Class->add_operation( { name=>'Key', type=>'Foreign', Params=>[ { Name => $pk_col }], visibility=>0, } );
lib/Autodia/Handler/DBI.pm view on Meta::CPAN
for my $field (@{$self->{tables}{$table}{fields}}) {
my $sth = $dbh->column_info( $schema || undef, $dbname, $esc_table, $field );
my $field_info = $sth->fetchrow_hashref;
$Class->add_attribute({
name => $field,
visibility => 0,
type => $field_info->{TYPE_NAME},
});
if ($guess_foreign_keys) {
if (my $dep = $self->_guess_foreign_key($table, $field)) {
# fix - need to handle multiple relations per table
push(@{$self->{foreign_tables}{$dep}}, {field => $field, table => $esc_table, class => $Class });
$Class->add_operation( { name=>'Key', type=>'Foreign', Params=>[ { Name => $field, Type => $field_info->{TYPE_NAME}, }], visibility=>0, } );
}
}
}
}
# fix - need to handle multiple relations per table
foreach my $fk_table (keys %{$self->{foreign_tables}} ) {
lib/Autodia/Handler/DBI.pm view on Meta::CPAN
# add Relationship to superclass
$Superclass->add_relation($Relationship);
# add Relationship to class
$Class->add_relation($Relationship);
# add Relationship to diagram
$self->{Diagram}->add_relation($Relationship);
return;
}
sub _guess_foreign_key {
my ($self, $table, $field) = @_;
my $is_fk = undef;
$field =~ s/'"`//g;
if ($field =~ m/^(.*)_u?id$/i) {
my $foreign_table = $1;
unless ($foreign_table eq $table) {
$is_fk = $foreign_table if ($self->{tables}{$foreign_table});
}
} elsif (($field ne $table ) && ($self->{tables}{$field})) {
( run in 0.668 second using v1.01-cache-2.11-cpan-702932259ff )