diff --git a/lib/SQL/Translator.pm b/lib/SQL/Translator.pm index 1f0c636d0..1cbfcee16 100644 --- a/lib/SQL/Translator.pm +++ b/lib/SQL/Translator.pm @@ -148,7 +148,7 @@ has filters => ( next; } else { - __PACKAGE__->debug("Adding $filt filter. Args:".Dumper(\@args)."\n"); + __PACKAGE__->debug("Adding $filt filter. Args:".Dumper(\@args)."\n") if __PACKAGE__->debugging; $filt = _load_sub("$filt\::filter", "SQL::Translator::Filter") || throw(__PACKAGE__->error); push @filters, [$filt,@args]; @@ -361,7 +361,7 @@ sub translate { return $self->error($msg); } } - $self->debug("Schema =\n", Dumper($self->schema), "\n"); + $self->debug("Schema =\n", Dumper($self->schema), "\n") if $self->debugging;; # Validate the schema if asked to. if ($self->validate) { diff --git a/lib/SQL/Translator/Producer/Diagram.pm b/lib/SQL/Translator/Producer/Diagram.pm index f415390e0..a12556b37 100644 --- a/lib/SQL/Translator/Producer/Diagram.pm +++ b/lib/SQL/Translator/Producer/Diagram.pm @@ -67,8 +67,8 @@ sub produce { my $schema = $t->schema; my $args = $t->producer_args; local $DEBUG = $t->debug; - debug("Schema =\n", Dumper( $schema )); - debug("Producer args =\n", Dumper( $args )); + debug("Schema =\n", Dumper( $schema )) if $DEBUG; + debug("Producer args =\n", Dumper( $args )) if $DEBUG; my $out_file = $args->{'out_file'} || ''; my $output_type = $args->{'output_type'} || 'png'; @@ -176,7 +176,7 @@ sub produce { debug("Processing table '$table_name'"); my @fields = $table->get_fields; - debug("Fields = ", join(', ', map { $_->name } @fields)); + debug("Fields = ", join(', ', map { $_->name } @fields)) if $DEBUG; my ( @fld_desc, $max_name, $max_desc ); for my $f ( @fields ) { diff --git a/lib/SQL/Translator/Producer/GraphViz.pm b/lib/SQL/Translator/Producer/GraphViz.pm index f17a9d320..3b8ef59d3 100644 --- a/lib/SQL/Translator/Producer/GraphViz.pm +++ b/lib/SQL/Translator/Producer/GraphViz.pm @@ -520,7 +520,7 @@ sub produce { debug("Processing table '$table_name'"); - debug("Fields = ", join(', ', map { $_->name } @fields)); + debug("Fields = ", join(', ', map { $_->name } @fields)) if $DEBUG; for my $f ( @fields ) { my $name = $f->name or next; diff --git a/lib/SQL/Translator/Producer/TTSchema.pm b/lib/SQL/Translator/Producer/TTSchema.pm index 5885d3b06..36f62b6ab 100644 --- a/lib/SQL/Translator/Producer/TTSchema.pm +++ b/lib/SQL/Translator/Producer/TTSchema.pm @@ -138,7 +138,7 @@ sub produce { my %tt_conf = exists $args->{tt_conf} ? %{$args->{tt_conf}} : (); # sqlt passes the producer args for _all_ producers in, so we use this # grep hack to test for the old usage. - debug(Dumper(\%tt_conf)); + debug(Dumper(\%tt_conf)) if $DEBUG; if ( grep /^[A-Z_]+$/, keys %$args ) { warn "Template config directly in the producer args is deprecated." ." Please use 'tt_conf' instead.\n"; diff --git a/lib/SQL/Translator/Schema/Table.pm b/lib/SQL/Translator/Schema/Table.pm index 789b9a160..a73b6b69c 100644 --- a/lib/SQL/Translator/Schema/Table.pm +++ b/lib/SQL/Translator/Schema/Table.pm @@ -303,22 +303,24 @@ sub add_field { $self->error( $field_class->error ); } - my $existing_order = { map { $_->order => $_->name } $self->get_fields }; + my @fields = values %{ $self->_fields }; # supplied order, possible unordered assembly if ( $field->order ) { - if($existing_order->{$field->order}) { + my %existing_order = map { $_->order => $_->name } @fields; + if($existing_order{$field->order}) { croak sprintf "Requested order '%d' for column '%s' conflicts with already existing column '%s'", $field->order, $field->name, - $existing_order->{$field->order}, + $existing_order{$field->order}, ; } } else { - my $last_field_no = max(keys %$existing_order) || 0; - if ( $last_field_no != scalar keys %$existing_order ) { + my @orders = map { $_->order } @fields; + my $last_field_no = max(@orders) || 0; + if ( $last_field_no != @orders ) { croak sprintf "Table '%s' field order incomplete - unable to auto-determine order for newly added field", $self->name,