Commit | Line | Data |
7a0ceaa1 |
1 | package SQL::Translator::Producer::SQLServer; |
2 | |
7a0ceaa1 |
3 | use strict; |
f27f9229 |
4 | use warnings; |
0c04c5a2 |
5 | our ( $DEBUG, $WARN ); |
da93ce68 |
6 | our $VERSION = '1.60'; |
7a0ceaa1 |
7 | $DEBUG = 1 unless defined $DEBUG; |
8 | |
7a0ceaa1 |
9 | use SQL::Translator::Schema::Constants; |
10 | use SQL::Translator::Utils qw(debug header_comment); |
c661b77d |
11 | use SQL::Translator::Generator::DDL::SQLServer; |
0a6e5a56 |
12 | |
7a0ceaa1 |
13 | sub produce { |
9a6c1bf9 |
14 | my $translator = shift; |
15 | SQL::Translator::Generator::DDL::SQLServer->new( |
16 | add_comments => !$translator->no_comments, |
f851dfea |
17 | add_drop_table => $translator->add_drop_table, |
9a6c1bf9 |
18 | )->schema($translator->schema) |
871f55d4 |
19 | } |
20 | |
056238d8 |
21 | 1; |
22 | |
056238d8 |
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 | |
22c0c10f |
36 | This is currently a thin wrapper around the nextgen |
37 | L<SQL::Translator::Generator::DDL::SQLServer> DDL maker. |
056238d8 |
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 | |
7a0ceaa1 |
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"; |
5c5997ef |
61 | $output .= "--\n-- View: $name\n--\n\n" unless $no_comments; |
3e0bcbfd |
62 | my $text = $_->sql(); |
e2fb9ad3 |
63 | $text =~ s/\r//g; |
5bb0a4ee |
64 | $output .= "$text\nGO\n"; |
7a0ceaa1 |
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"; |
5c5997ef |
74 | $output .= "--\n-- Procedure: $name\n--\n\n" unless $no_comments; |
3e0bcbfd |
75 | my $text = $_->sql(); |
028386aa |
76 | $text =~ s/\r//g; |
5bb0a4ee |
77 | $output .= "$text\nGO\n"; |
7a0ceaa1 |
78 | } |
7a0ceaa1 |
79 | |
80 | =head1 SEE ALSO |
81 | |
22c0c10f |
82 | L<SQL::Translator> |
7a0ceaa1 |
83 | |
84 | =head1 AUTHORS |
85 | |
22c0c10f |
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. |
7a0ceaa1 |
97 | |
98 | =cut |