Commit | Line | Data |
d4c630fa |
1 | use strict; |
b0f5a88b |
2 | use warnings; |
d4c630fa |
3 | use Test::More; |
d4c630fa |
4 | |
b0f5a88b |
5 | use SQL::Translator; |
d4c630fa |
6 | use SQL::Translator::Object::View; |
d4c630fa |
7 | |
8 | { |
b0f5a88b |
9 | my $sqlt = SQL::Translator->new( to => 'SQLite' ); |
10 | my $producer = $sqlt->_producer; |
11 | |
d4c630fa |
12 | my $view1 = SQL::Translator::Object::View->new( name => 'view_foo', |
13 | fields => [qw/id name/], |
14 | sql => 'SELECT id, name FROM thing', |
15 | extra => { |
16 | temporary => 1, |
17 | if_not_exists => 1, |
18 | }); |
b0f5a88b |
19 | |
d4c630fa |
20 | my $create_opts = { no_comments => 1 }; |
b0f5a88b |
21 | my $view1_sql1 = $producer->create_view($view1, $create_opts); |
d4c630fa |
22 | |
23 | my $view_sql_replace = "CREATE TEMPORARY VIEW IF NOT EXISTS view_foo AS |
24 | SELECT id, name FROM thing"; |
25 | is($view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL'); |
26 | |
d4c630fa |
27 | my $view2 = SQL::Translator::Object::View->new( name => 'view_foo', |
28 | fields => [qw/id name/], |
29 | sql => 'SELECT id, name FROM thing',); |
30 | |
b0f5a88b |
31 | my $view1_sql2 = $producer->create_view($view2, $create_opts); |
d4c630fa |
32 | my $view_sql_noreplace = "CREATE VIEW view_foo AS |
33 | SELECT id, name FROM thing"; |
34 | is($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL'); |
35 | } |
36 | |
37 | done_testing; |