From: Arthur Axel 'fREW' Schmidt Date: Tue, 8 Mar 2011 03:59:42 +0000 (-0600) Subject: factor out some basic constraints X-Git-Tag: v0.11011~27^2~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e6fcfabf1d69112e7ce8fcfe2fa6d798f1132823;p=dbsrgits%2FSQL-Translator.git factor out some basic constraints --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLServer.pm b/lib/SQL/Translator/Generator/DDL/SQLServer.pm index c751e1d..85be5ab 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLServer.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLServer.pm @@ -56,5 +56,20 @@ sub field_type_size { sub field_autoinc { ( $_[1]->is_auto_increment ? 'IDENTITY' : () ) } +sub primary_key_constraint { + 'CONSTRAINT ' . + $_[0]->shim->quote($_[1]->name || $_[1]->table->name . '_pk') . + ' PRIMARY KEY (' . + join( ', ', map $_[0]->shim->quote($_), $_[1]->fields ) . + ')' +} + +sub index { + 'CREATE INDEX ' . + $_[0]->shim->quote($_[1]->name || $_[1]->table->name . '_idx') . + ' ON ' . $_[0]->shim->quote($_[1]->table->name) . + ' (' . join( ', ', map $_[0]->shim->quote($_), $_[1]->fields ) . ');' +} + 1; diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index 7acf128..cb93c64 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -207,10 +207,7 @@ sub produce { if ( $type eq PRIMARY_KEY ) { - $name = ($name ? unreserve($name) : mk_name( $table_name . '_pk' )); - $c_def = - "CONSTRAINT $name PRIMARY KEY ". - '(' . join( ', ', @fields ) . ')'; + $c_def = $future->primary_key_constraint($constraint) } elsif ( $type eq UNIQUE ) { $name = $name_ur || mk_name( $table_name . '_uc' ); @@ -234,11 +231,7 @@ sub produce { # Indices # for my $index ( $table->get_indices ) { - my $idx_name = $index->name || mk_name($table_name . '_idx'); - my $idx_name_ur = unreserve($idx_name); - push @index_defs, - "CREATE INDEX $idx_name_ur ON $table_name_ur (". - join( ', ', map unreserve($_), $index->fields ) . ");"; + push @index_defs, $future->index($index) } my $create_statement = "";