From: Arthur Axel 'fREW' Schmidt Date: Thu, 10 Mar 2011 04:11:43 +0000 (-0600) Subject: add remove_table_constraints to future X-Git-Tag: v0.11011~27^2~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=97a16cf44029e070da62cdd2fb081defb6e3f986;p=dbsrgits%2FSQL-Translator.git add remove_table_constraints to future --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLServer.pm b/lib/SQL/Translator/Generator/DDL/SQLServer.pm index 9482281..8425a0a 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLServer.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLServer.pm @@ -173,5 +173,13 @@ sub drop_table { " DROP TABLE $q_name;\n" } +sub remove_table_constraints { + my ($self, $table) = @_; + my $name = $table->name; + my $q_name = $self->quote($name); + "IF EXISTS (SELECT name FROM sysobjects WHERE name = '$name' AND type = 'U')" . + " ALTER TABLE $q_name NOCHECK CONSTRAINT all;\n" +} + 1; diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index 0208141..fe29c9b 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -27,9 +27,7 @@ sub produce { my @tables = sort { $b->order <=> $a->order } $schema->get_tables; $output .= "--\n-- Turn off constraints\n--\n\n" unless $no_comments; foreach my $table (@tables) { - my $name = $table->name; - my $q_name = unreserve($name); - $output .= "IF EXISTS (SELECT name FROM sysobjects WHERE name = '$name' AND type = 'U') ALTER TABLE $q_name NOCHECK CONSTRAINT all;\n" + $output .= $future->remove_table_constraints($table) } $output .= "\n"; $output .= "--\n-- Drop tables\n--\n\n" unless $no_comments;