package SQL::Translator::Schema;
-# ----------------------------------------------------------------------
-# Copyright (C) 2002-2009 SQLFairy Authors
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307 USA
-# -------------------------------------------------------------------
-
=pod
=head1 NAME
=cut
use strict;
+use warnings;
use SQL::Translator::Schema::Constants;
use SQL::Translator::Schema::Procedure;
use SQL::Translator::Schema::Table;
use SQL::Translator::Schema::View;
use SQL::Translator::Utils 'parse_list_arg';
+use Carp;
use base 'SQL::Translator::Schema::Object';
-use vars qw[ $VERSION ];
-
-$VERSION = '1.59';
+our $VERSION = '1.59';
__PACKAGE__->_attributes(qw/name database translator/);
return $self;
}
-# ----------------------------------------------------------------------
+# FIXME - to be removed, together with the SQL::Translator::Schema::Graph* stuff
+# looks like a remnant of the Turnkey project integration back in 2003-4
+# Appears to be quite dead
sub as_graph {
-=pod
-
-=head2 as_graph
-
-Returns the schema as an L<SQL::Translator::Schema::Graph> object.
+ eval { require Class::MakeMethods }
+ or croak 'You need to install the CPAN dependency Class::MakeMethods to use as_graph()';
-=cut
require SQL::Translator::Schema::Graph;
my $self = shift;
translator => $self->translator );
}
-# ----------------------------------------------------------------------
sub as_graph_pm {
=pod
my $self = shift;
my $g = Graph::Directed->new;
-
- for my $table ( $self->get_tables ) {
+
+ for my $table ( $self->get_tables ) {
my $tname = $table->name;
$g->add_vertex( $tname );
-
+
for my $field ( $table->get_fields ) {
if ( $field->is_foreign_key ) {
my $fktable = $field->foreign_key_reference->reference_table;
return $g;
}
-# ----------------------------------------------------------------------
sub add_table {
=pod
Add a table object. Returns the new SQL::Translator::Schema::Table object.
The "name" parameter is required. If you try to create a table with the
-same name as an existing table, you will get an error and the table will
+same name as an existing table, you will get an error and the table will
not be created.
my $t1 = $schema->add_table( name => 'foo' ) or die $schema->error;
return $table;
}
-# ----------------------------------------------------------------------
sub drop_table {
=pod
return $table;
}
-# ----------------------------------------------------------------------
sub add_procedure {
=pod
return $procedure;
}
-# ----------------------------------------------------------------------
sub drop_procedure {
=pod
return $proc;
}
-# ----------------------------------------------------------------------
sub add_trigger {
=pod
Add a trigger object. Returns the new SQL::Translator::Schema::Trigger object.
The "name" parameter is required. If you try to create a trigger with the
-same name as an existing trigger, you will get an error and the trigger will
+same name as an existing trigger, you will get an error and the trigger will
not be created.
my $t1 = $schema->add_trigger( name => 'foo' );
return $trigger;
}
-# ----------------------------------------------------------------------
sub drop_trigger {
=pod
return $trigger;
}
-# ----------------------------------------------------------------------
sub add_view {
=pod
Add a view object. Returns the new SQL::Translator::Schema::View object.
The "name" parameter is required. If you try to create a view with the
-same name as an existing view, you will get an error and the view will
+same name as an existing view, you will get an error and the view will
not be created.
my $v1 = $schema->add_view( name => 'foo' );
return $view;
}
-# ----------------------------------------------------------------------
sub drop_view {
=pod
return $view;
}
-# ----------------------------------------------------------------------
sub database {
=pod
return $self->{'database'} || '';
}
-# ----------------------------------------------------------------------
sub is_valid {
=pod
return 1;
}
-# ----------------------------------------------------------------------
sub get_procedure {
=pod
return $self->{'procedures'}{$procedure_name};
}
-# ----------------------------------------------------------------------
sub get_procedures {
=pod
}
}
-# ----------------------------------------------------------------------
sub get_table {
=pod
my $table_name = shift or return $self->error('No table name');
my $case_insensitive = shift;
if ( $case_insensitive ) {
- $table_name = uc($table_name);
- foreach my $table ( keys %{$self->{tables}} ) {
- return $self->{tables}{$table} if $table_name eq uc($table);
- }
- return $self->error(qq[Table "$table_name" does not exist]);
+ $table_name = uc($table_name);
+ foreach my $table ( keys %{$self->{tables}} ) {
+ return $self->{tables}{$table} if $table_name eq uc($table);
+ }
+ return $self->error(qq[Table "$table_name" does not exist]);
}
return $self->error(qq[Table "$table_name" does not exist])
unless exists $self->{'tables'}{$table_name};
return $self->{'tables'}{$table_name};
}
-# ----------------------------------------------------------------------
sub get_tables {
=pod
}
}
-# ----------------------------------------------------------------------
sub get_trigger {
=pod
return $self->{'triggers'}{$trigger_name};
}
-# ----------------------------------------------------------------------
sub get_triggers {
=pod
}
}
-# ----------------------------------------------------------------------
sub get_view {
=pod
return $self->{'views'}{$view_name};
}
-# ----------------------------------------------------------------------
sub get_views {
=pod
}
}
-# ----------------------------------------------------------------------
sub make_natural_joins {
=pod
=item * join_pk_only
-A True or False argument which determins whether or not to perform
+A True or False argument which determins whether or not to perform
the joins from primary keys to fields of the same name in other tables
=item * skip_fields
return 1;
}
-# ----------------------------------------------------------------------
sub name {
=pod
return $self->{'name'} || '';
}
-# ----------------------------------------------------------------------
sub translator {
=pod
return $self->{'translator'};
}
-# ----------------------------------------------------------------------
sub DESTROY {
my $self = shift;
undef $_ for values %{ $self->{'tables'} };
1;
-# ----------------------------------------------------------------------
-
=pod
=head1 AUTHOR