Fixed problem with "deep recursion."
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Schema / Table.pm
index a263cee..878debe 100644 (file)
@@ -1,7 +1,7 @@
 package SQL::Translator::Schema::Table;
 
 # ----------------------------------------------------------------------
-# $Id: Table.pm,v 1.7 2003-06-06 22:36:09 kycl4rk Exp $
+# $Id: Table.pm,v 1.14 2003-08-21 20:27:04 kycl4rk Exp $
 # ----------------------------------------------------------------------
 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
 #
@@ -50,7 +50,7 @@ use SQL::Translator::Schema::Index;
 use base 'Class::Base';
 use vars qw( $VERSION $FIELD_ORDER );
 
-$VERSION = 1.00;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/;
 
 # ----------------------------------------------------------------------
 sub init {
@@ -118,16 +118,26 @@ C<SQL::Translator::Schema::Constraint> object.
     # If we're trying to add a PK when one is already defined,
     # then just add the fields to the existing definition.
     #
-    my $ok = 0;
+    my $ok = 1;
     my $pk = $self->primary_key;
     if ( $pk && $constraint->type eq PRIMARY_KEY ) {
         $self->primary_key( $constraint->fields );
         $constraint = $pk;
+        $ok         = 0;
     }
-    else {
+    elsif ( $constraint->type eq PRIMARY_KEY ) {
+        for my $fname ( $constraint->fields ) {
+            if ( my $f = $self->get_field( $fname ) ) {
+                $f->is_primary_key( 1 );
+            }
+        }
+    }
+    #
+    # See if another constraint of the same type 
+    # covers the same fields.
+    #
+    elsif ( $constraint->type ne CHECK_C ) {
         my @field_names = $constraint->fields;
-        $ok = 1;
-
         for my $c ( 
             grep { $_->type eq $constraint->type } 
             $self->get_constraints 
@@ -263,12 +273,23 @@ all the comments joined on newlines.
 
 =cut
 
-    my $self = shift;
-    push @{ $self->{'comments'} }, @_ if @_;
+    my $self     = shift;
+    my @comments = ref $_[0] ? @{ $_[0] } : @_;
+
+    for my $arg ( @comments ) {
+        $arg = $arg->[0] if ref $arg;
+        push @{ $self->{'comments'} }, $arg if defined $arg && $arg;
+    }
 
-    return wantarray 
-        ? @{ $self->{'comments'} || [] }
-        : join( "\n", @{ $self->{'comments'} || [] } );
+    if ( @{ $self->{'comments'} || [] } ) {
+        return wantarray 
+            ? @{ $self->{'comments'} }
+            : join( "\n", @{ $self->{'comments'} } )
+        ;
+    } 
+    else {
+        return wantarray ? () : undef;
+    }
 }
 
 # ----------------------------------------------------------------------