X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FSchema%2FConstraint.pm;h=4a36725116e43505c244366bb6e979ec08c3b3ab;hb=4ab3763d2ad756c236b757306989cafa08e7f35e;hp=89f3403a3dd73bd94225328569e7656b4b6e41a4;hpb=383067ff7eea362432f044a3a7f054664b235f68;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Schema/Constraint.pm b/lib/SQL/Translator/Schema/Constraint.pm index 89f3403..4a36725 100644 --- a/lib/SQL/Translator/Schema/Constraint.pm +++ b/lib/SQL/Translator/Schema/Constraint.pm @@ -1,9 +1,7 @@ package SQL::Translator::Schema::Constraint; # ---------------------------------------------------------------------- -# $Id: Constraint.pm,v 1.17 2005-06-28 22:55:19 duality72 Exp $ -# ---------------------------------------------------------------------- -# Copyright (C) 2002-4 SQLFairy Authors +# 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 @@ -51,7 +49,7 @@ use base 'SQL::Translator::Schema::Object'; use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT); -$VERSION = sprintf "%d.%02d", q$Revision: 1.17 $ =~ /(\d+)\.(\d+)/; +$VERSION = '1.59'; my %VALID_CONSTRAINT_TYPE = ( PRIMARY_KEY, 1, @@ -276,7 +274,7 @@ avoid the overload magic of the Field objects returned by the fields method. =cut my $self = shift; - return wantarray ? @{ $self->{'fields'} || [] } : $self->{'fields'}; + return wantarray ? @{ $self->{'fields'} || [] } : ($self->{'fields'} || ''); } # ---------------------------------------------------------------------- @@ -539,22 +537,53 @@ Determines if this constraint is the same as another my $self = shift; my $other = shift; my $case_insensitive = shift; + my $ignore_constraint_names = shift; return 0 unless $self->SUPER::equals($other); - return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name; + return 0 unless $self->type eq $other->type; + unless ($ignore_constraint_names) { + return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name; + } return 0 unless $self->deferrable eq $other->deferrable; - return 0 unless $self->is_valid eq $other->is_valid; + #return 0 unless $self->is_valid eq $other->is_valid; return 0 unless $case_insensitive ? uc($self->table->name) eq uc($other->table->name) : $self->table->name eq $other->table->name; return 0 unless $self->expression eq $other->expression; - return 0 unless $self->_compare_objects(scalar $self->field_names, scalar $other->field_names); - return 0 unless $self->reference_table eq $other->reference_table; - return 0 unless $self->_compare_objects($self->reference_fields, $other->reference_fields); + + # Check fields, regardless of order + my %otherFields = (); # create a hash of the other fields + foreach my $otherField ($other->fields) { + $otherField = uc($otherField) if $case_insensitive; + $otherFields{$otherField} = 1; + } + foreach my $selfField ($self->fields) { # check for self fields in hash + $selfField = uc($selfField) if $case_insensitive; + return 0 unless $otherFields{$selfField}; + delete $otherFields{$selfField}; + } + # Check all other fields were accounted for + return 0 unless keys %otherFields == 0; + + # Check reference fields, regardless of order + my %otherRefFields = (); # create a hash of the other reference fields + foreach my $otherRefField ($other->reference_fields) { + $otherRefField = uc($otherRefField) if $case_insensitive; + $otherRefFields{$otherRefField} = 1; + } + foreach my $selfRefField ($self->reference_fields) { # check for self reference fields in hash + $selfRefField = uc($selfRefField) if $case_insensitive; + return 0 unless $otherRefFields{$selfRefField}; + delete $otherRefFields{$selfRefField}; + } + # Check all other reference fields were accounted for + return 0 unless keys %otherRefFields == 0; + + return 0 unless $case_insensitive ? uc($self->reference_table) eq uc($other->reference_table) : $self->reference_table eq $other->reference_table; return 0 unless $self->match_type eq $other->match_type; return 0 unless $self->on_delete eq $other->on_delete; return 0 unless $self->on_update eq $other->on_update; - return 0 unless $self->_compare_objects($self->options, $other->options); - return 0 unless $self->_compare_objects($self->extra, $other->extra); + return 0 unless $self->_compare_objects(scalar $self->options, scalar $other->options); + return 0 unless $self->_compare_objects(scalar $self->extra, scalar $other->extra); return 1; }