From: Peter Rabbitson Date: Thu, 18 Jun 2009 12:20:57 +0000 (+0000) Subject: Mssql does not understand ON DELETE RESTRICT X-Git-Tag: v0.11008~146 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5bac76bc7960f05f858628266ab1c057491845b2;p=dbsrgits%2FSQL-Translator.git Mssql does not understand ON DELETE RESTRICT --- diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index b211847..5e91cc8 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -275,7 +275,7 @@ sub produce { $constraint->reference_fields; next unless @fields; - my $c_def; + my $c_def; if ( $type eq PRIMARY_KEY ) { $name ||= mk_name( $table_name . '_pk' ); $c_def = @@ -284,19 +284,26 @@ sub produce { } elsif ( $type eq FOREIGN_KEY ) { $name ||= mk_name( $table_name . '_fk' ); + my $on_delete = uc ($constraint->on_delete || ''); + my $on_update = uc ($constraint->on_update || ''); + + # The default implicit constraint action in MSSQL is RESTRICT + # but you can not specify it explicitly. Go figure :) + for ($on_delete, $on_update) { + undef $_ if $_ eq 'RESTRICT' + } + $c_def = "CONSTRAINT $name FOREIGN KEY". ' (' . join( ', ', @fields ) . ') REFERENCES '. $constraint->reference_table. ' (' . join( ', ', @rfields ) . ')'; - my $on_delete = $constraint->on_delete; - if ( $on_delete && $on_delete ne "NO ACTION") { - $c_def .= " ON DELETE $on_delete"; - } - my $on_update = $constraint->on_update; - if ( $on_update && $on_update ne "NO ACTION") { - $c_def .= " ON UPDATE $on_update"; - } + if ( $on_delete && $on_delete ne "NO ACTION") { + $c_def .= " ON DELETE $on_delete"; + } + if ( $on_update && $on_update ne "NO ACTION") { + $c_def .= " ON UPDATE $on_update"; + } } elsif ( $type eq UNIQUE ) { $name ||= mk_name( $table_name . '_uc' );