X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer%2FSQLServer.pm;h=ed9d156b272c53a498a06ae163b36dcc36569011;hb=c9c8f3e19f6af2ce0fe5cacd55b87b1d88c6e5eb;hp=fe29c9b007fb1c0d19b0781f9a24d4475b2b6aa6;hpb=97a16cf44029e070da62cdd2fb081defb6e3f986;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index fe29c9b..ed9d156 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -6,86 +6,20 @@ our ( $DEBUG, $WARN ); our $VERSION = '1.59'; $DEBUG = 1 unless defined $DEBUG; -use Data::Dumper; use SQL::Translator::Schema::Constants; use SQL::Translator::Utils qw(debug header_comment); use SQL::Translator::Generator::DDL::SQLServer; -my $future = SQL::Translator::Generator::DDL::SQLServer->new(); - sub produce { - my $translator = shift; - my $no_comments = $translator->no_comments; - my $add_drop_table = $translator->add_drop_table; - my $schema = $translator->schema; - - my $output; - $output .= header_comment."\n" unless ($no_comments); - - # Generate the DROP statements. - if ($add_drop_table) { - 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) { - $output .= $future->remove_table_constraints($table) - } - $output .= "\n"; - $output .= "--\n-- Drop tables\n--\n\n" unless $no_comments; - foreach my $table (@tables) { - $output .= $future->drop_table($table); - } - } - - # these need to be added separately, as tables may not exist yet - my @foreign_constraints = (); - - for my $table ( grep { $_->name } $schema->get_tables ) { - my $table_name_ur = unreserve($table->name); - - my ( @comments ); - - push @comments, "\n\n--\n-- Table: $table_name_ur\n--" - unless $no_comments; - - push @comments, map { "-- $_" } $table->comments; - - push @foreign_constraints, map $future->foreign_key_constraint($_), - grep { $_->type eq FOREIGN_KEY } $table->get_constraints; - - $output .= join( "\n\n", - @comments, - # index defs - $future->table($table), - (map $future->unique_constraint_multiple($_), - grep { - $_->type eq UNIQUE && - grep { $_->is_nullable } $_->fields - } $table->get_constraints), - - (map $future->index($_), $table->get_indices) - ); - } - -# Add FK constraints - $output .= join ("\n", '', @foreign_constraints) if @foreign_constraints; - -# create view/procedure are NOT prepended to the input $sql, needs -# to be filled in with the proper syntax - - return $output; + my $translator = shift; + SQL::Translator::Generator::DDL::SQLServer->new( + add_comments => !$translator->no_comments, + add_drop_table => $translator->add_drop_table, + )->schema($translator->schema) } -sub unreserve { $future->quote($_[0]) } - 1; -=pod - -=head1 SQLServer Create Table Syntax - -TODO - - =head1 NAME SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator @@ -99,8 +33,8 @@ SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator =head1 DESCRIPTION -BB This is still fairly early code, basically a hacked version of the -Sybase Producer (thanks Sam, Paul and Ken for doing the real work ;-) +This is currently a thin wrapper around the nextgen +L DDL maker. =head1 Extra Attributes @@ -145,11 +79,20 @@ List of values for an enum field. =head1 SEE ALSO -SQL::Translator. +L =head1 AUTHORS -Mark Addison Egrommit@users.sourceforge.netE - Bulk of code from -Sybase producer, I just tweaked it for SQLServer. Thanks. +See the included AUTHORS file: +L + +=head1 COPYRIGHT + +Copyright (c) 2012 the SQL::Translator L as listed above. + +=head1 LICENSE + +This code is free software and may be distributed under the same terms as Perl +itself. =cut