Commit | Line | Data |
7a0ceaa1 |
1 | package SQL::Translator::Producer::SQLServer; |
2 | |
7a0ceaa1 |
3 | use strict; |
f27f9229 |
4 | use warnings; |
0c04c5a2 |
5 | our ( $DEBUG, $WARN ); |
6 | our $VERSION = '1.59'; |
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, |
17 | add_drop_tables => $translator->add_drop_table, |
18 | )->schema($translator->schema) |
871f55d4 |
19 | } |
20 | |
056238d8 |
21 | 1; |
22 | |
6fac033a |
23 | =pod |
e2fb9ad3 |
24 | |
056238d8 |
25 | =head1 SQLServer Create Table Syntax |
26 | |
27 | TODO |
28 | |
29 | |
30 | =head1 NAME |
31 | |
32 | SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator |
33 | |
34 | =head1 SYNOPSIS |
35 | |
36 | use SQL::Translator; |
37 | |
38 | my $t = SQL::Translator->new( parser => '...', producer => 'SQLServer' ); |
39 | $t->translate; |
40 | |
41 | =head1 DESCRIPTION |
42 | |
43 | B<WARNING>B This is still fairly early code, basically a hacked version of the |
44 | Sybase Producer (thanks Sam, Paul and Ken for doing the real work ;-) |
45 | |
46 | =head1 Extra Attributes |
47 | |
48 | =over 4 |
49 | |
50 | =item field.list |
51 | |
52 | List of values for an enum field. |
53 | |
54 | =back |
55 | |
56 | =head1 TODO |
57 | |
58 | * !! Write some tests !! |
59 | * Reserved words list needs updating to SQLServer. |
60 | * Triggers, Procedures and Views DO NOT WORK |
61 | |
62 | |
7a0ceaa1 |
63 | # Text of view is already a 'create view' statement so no need to |
64 | # be fancy |
65 | foreach ( $schema->get_views ) { |
66 | my $name = $_->name(); |
67 | $output .= "\n\n"; |
5c5997ef |
68 | $output .= "--\n-- View: $name\n--\n\n" unless $no_comments; |
3e0bcbfd |
69 | my $text = $_->sql(); |
e2fb9ad3 |
70 | $text =~ s/\r//g; |
5bb0a4ee |
71 | $output .= "$text\nGO\n"; |
7a0ceaa1 |
72 | } |
73 | |
74 | # Text of procedure already has the 'create procedure' stuff |
75 | # so there is no need to do anything fancy. However, we should |
76 | # think about doing fancy stuff with granting permissions and |
77 | # so on. |
78 | foreach ( $schema->get_procedures ) { |
79 | my $name = $_->name(); |
80 | $output .= "\n\n"; |
5c5997ef |
81 | $output .= "--\n-- Procedure: $name\n--\n\n" unless $no_comments; |
3e0bcbfd |
82 | my $text = $_->sql(); |
028386aa |
83 | $text =~ s/\r//g; |
5bb0a4ee |
84 | $output .= "$text\nGO\n"; |
7a0ceaa1 |
85 | } |
7a0ceaa1 |
86 | |
87 | =head1 SEE ALSO |
88 | |
89 | SQL::Translator. |
90 | |
91 | =head1 AUTHORS |
92 | |
93 | Mark Addison E<lt>grommit@users.sourceforge.netE<gt> - Bulk of code from |
94 | Sybase producer, I just tweaked it for SQLServer. Thanks. |
95 | |
96 | =cut |