From: Ken Youens-Clark Date: Thu, 21 Aug 2003 18:11:45 +0000 (+0000) Subject: Some special logic to better handle check constraints (which don't have X-Git-Tag: v0.04~244 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=53ded04a8fbdac49d038084cba9fef267d998f42;p=dbsrgits%2FSQL-Translator.git Some special logic to better handle check constraints (which don't have "fields"), also wasn't setting "expression" in "init," better returning of "fields." --- diff --git a/lib/SQL/Translator/Schema/Constraint.pm b/lib/SQL/Translator/Schema/Constraint.pm index 4764d90..bf38e1c 100644 --- a/lib/SQL/Translator/Schema/Constraint.pm +++ b/lib/SQL/Translator/Schema/Constraint.pm @@ -1,7 +1,7 @@ package SQL::Translator::Schema::Constraint; # ---------------------------------------------------------------------- -# $Id: Constraint.pm,v 1.7 2003-06-27 16:47:40 kycl4rk Exp $ +# $Id: Constraint.pm,v 1.8 2003-08-21 18:11:45 kycl4rk Exp $ # ---------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark # @@ -51,7 +51,7 @@ use SQL::Translator::Utils 'parse_list_arg'; use base 'Class::Base'; use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT); -$VERSION = sprintf "%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/; my %VALID_CONSTRAINT_TYPE = ( PRIMARY_KEY, 1, @@ -87,11 +87,12 @@ Object constructor. my ( $self, $config ) = @_; my @fields = qw[ table name type fields reference_fields reference_table - match_type on_delete on_update + match_type on_delete on_update expression ]; for my $arg ( @fields ) { next unless $config->{ $arg }; + next if ref $config->{ $arg } eq 'ARRAY' && ! @{ $config->{ $arg } }; defined $self->$arg( $config->{ $arg } ) or return; } @@ -245,7 +246,12 @@ names and keep them in order by the first occurrence of a field name. $self->{'fields'} = \@unique; } - return wantarray ? @{ $self->{'fields'} || [] } : $self->{'fields'}; + if ( @{ $self->{'fields'} || [] } ) { + return wantarray ? @{ $self->{'fields'} } : $self->{'fields'}; + } + else { + return wantarray ? () : undef; + } } # ----------------------------------------------------------------------