1 package SQL::Translator::Producer::SQLServer;
7 $DEBUG = 1 unless defined $DEBUG;
9 use SQL::Translator::Schema::Constants;
10 use SQL::Translator::Utils qw(debug header_comment);
11 use SQL::Translator::Generator::DDL::SQLServer;
14 my $translator = shift;
15 my $future = SQL::Translator::Generator::DDL::SQLServer->new(
16 add_comments => !$translator->no_comments,
17 add_drop_tables => $translator->add_drop_table,
20 my $schema = $translator->schema;
22 my $output = $future->header_comments
23 . $future->drop_tables($schema);
25 for my $table ( grep { $_->name } $schema->get_tables ) {
26 $output .= join( "\n\n",
27 $future->table_comments($table),
29 $future->table($table),
30 (map $future->unique_constraint_multiple($_),
33 grep { $_->is_nullable } $_->fields
34 } $table->get_constraints),
36 (map $future->index($_), $table->get_indices)
40 my @foreign_constraints = $future->foreign_key_constraints($schema);
41 $output .= join ("\n", '', @foreign_constraints) if @foreign_constraints;
50 =head1 SQLServer Create Table Syntax
57 SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator
63 my $t = SQL::Translator->new( parser => '...', producer => 'SQLServer' );
68 B<WARNING>B This is still fairly early code, basically a hacked version of the
69 Sybase Producer (thanks Sam, Paul and Ken for doing the real work ;-)
71 =head1 Extra Attributes
77 List of values for an enum field.
83 * !! Write some tests !!
84 * Reserved words list needs updating to SQLServer.
85 * Triggers, Procedures and Views DO NOT WORK
88 # Text of view is already a 'create view' statement so no need to
90 foreach ( $schema->get_views ) {
91 my $name = $_->name();
93 $output .= "--\n-- View: $name\n--\n\n" unless $no_comments;
96 $output .= "$text\nGO\n";
99 # Text of procedure already has the 'create procedure' stuff
100 # so there is no need to do anything fancy. However, we should
101 # think about doing fancy stuff with granting permissions and
103 foreach ( $schema->get_procedures ) {
104 my $name = $_->name();
106 $output .= "--\n-- Procedure: $name\n--\n\n" unless $no_comments;
107 my $text = $_->sql();
109 $output .= "$text\nGO\n";
118 Mark Addison E<lt>grommit@users.sourceforge.netE<gt> - Bulk of code from
119 Sybase producer, I just tweaked it for SQLServer. Thanks.