6c9d21ba9602912190572bce8629a7121e11ac7e
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / SQLServer.pm
1 package SQL::Translator::Producer::SQLServer;
2
3 use strict;
4 use warnings;
5 our ( $DEBUG, $WARN );
6 our $VERSION = '1.61';
7 $DEBUG = 1 unless defined $DEBUG;
8
9 use SQL::Translator::Schema::Constants;
10 use SQL::Translator::Utils qw(debug header_comment);
11 use SQL::Translator::Generator::DDL::SQLServer;
12
13 sub produce {
14   my $translator = shift;
15   SQL::Translator::Generator::DDL::SQLServer->new(
16     add_comments    => !$translator->no_comments,
17     add_drop_table => $translator->add_drop_table,
18   )->schema($translator->schema)
19 }
20
21 1;
22
23 =head1 NAME
24
25 SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator
26
27 =head1 SYNOPSIS
28
29   use SQL::Translator;
30
31   my $t = SQL::Translator->new( parser => '...', producer => 'SQLServer' );
32   $t->translate;
33
34 =head1 DESCRIPTION
35
36 This is currently a thin wrapper around the nextgen
37 L<SQL::Translator::Generator::DDL::SQLServer> DDL maker.
38
39 =head1 Extra Attributes
40
41 =over 4
42
43 =item field.list
44
45 List of values for an enum field.
46
47 =back
48
49 =head1 TODO
50
51  * !! Write some tests !!
52  * Reserved words list needs updating to SQLServer.
53  * Triggers, Procedures and Views DO NOT WORK
54
55
56     # Text of view is already a 'create view' statement so no need to
57     # be fancy
58     foreach ( $schema->get_views ) {
59         my $name = $_->name();
60         $output .= "\n\n";
61         $output .= "--\n-- View: $name\n--\n\n" unless $no_comments;
62         my $text = $_->sql();
63         $text =~ s/\r//g;
64         $output .= "$text\nGO\n";
65     }
66
67     # Text of procedure already has the 'create procedure' stuff
68     # so there is no need to do anything fancy. However, we should
69     # think about doing fancy stuff with granting permissions and
70     # so on.
71     foreach ( $schema->get_procedures ) {
72         my $name = $_->name();
73         $output .= "\n\n";
74         $output .= "--\n-- Procedure: $name\n--\n\n" unless $no_comments;
75         my $text = $_->sql();
76       $text =~ s/\r//g;
77         $output .= "$text\nGO\n";
78     }
79
80 =head1 SEE ALSO
81
82 L<SQL::Translator>
83
84 =head1 AUTHORS
85
86 See the included AUTHORS file:
87 L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>
88
89 =head1 COPYRIGHT
90
91 Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above.
92
93 =head1 LICENSE
94
95 This code is free software and may be distributed under the same terms as Perl
96 itself.
97
98 =cut