# Header. Should this look like what mysqldump produces?
my $extra = $view->extra;
- my $create = '';
- $create .= "--\n-- View: ${view_name}\n--\n" unless $options->{no_comments};
- $create .= "DROP VIEW IF EXISTS $view_name;\n" if $add_drop_view;
- $create .= 'CREATE';
- $create .= " TEMPORARY" if exists($extra->{temporary}) && $extra->{temporary};
- $create .= ' VIEW';
- $create .= " IF NOT EXISTS" if exists($extra->{if_not_exists}) && $extra->{if_not_exists};
- $create .= " ${view_name}";
+ my @create;
+ push @create, "DROP VIEW IF EXISTS $view_name" if $add_drop_view;
+
+ my $create_view = 'CREATE';
+ $create_view .= " TEMPORARY" if exists($extra->{temporary}) && $extra->{temporary};
+ $create_view .= ' VIEW';
+ $create_view .= " IF NOT EXISTS" if exists($extra->{if_not_exists}) && $extra->{if_not_exists};
+ $create_view .= " ${view_name}";
if( my $sql = $view->sql ){
- $create .= " AS\n ${sql}";
+ $create_view .= " AS\n ${sql}";
}
- return $create;
+ push @create, $create_view;
+
+ # Tack the comment onto the first statement.
+ unless ($options->{no_comments}) {
+ $create[0] = "--\n-- View: ${view_name}\n--\n" . $create[0];
+ }
+
+ return @create;
}
);
DROP VIEW IF EXISTS email_list;
+
CREATE VIEW email_list AS
SELECT email FROM Basic WHERE (email IS NOT NULL);
id INTEGER PRIMARY KEY NOT NULL,
num numeric(10,2)
)',
- 'DROP VIEW IF EXISTS email_list;
-CREATE VIEW email_list AS
+ 'DROP VIEW IF EXISTS email_list',
+ 'CREATE VIEW email_list AS
SELECT email FROM Basic WHERE (email IS NOT NULL)',
'DROP TRIGGER IF EXISTS foo_trigger',
'CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END',
if_not_exists => 1,
});
my $create_opts = { no_comments => 1 };
- my $view1_sql1 = SQL::Translator::Producer::SQLite::create_view($view1, $create_opts);
+ my $view1_sql1 = [ SQL::Translator::Producer::SQLite::create_view($view1, $create_opts) ];
- my $view_sql_replace = "CREATE TEMPORARY VIEW IF NOT EXISTS view_foo AS
- SELECT id, name FROM thing";
- is($view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL');
+ my $view_sql_replace = [ "CREATE TEMPORARY VIEW IF NOT EXISTS view_foo AS
+ SELECT id, name FROM thing" ];
+ is_deeply($view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL');
my $view2 = SQL::Translator::Schema::View->new( name => 'view_foo',
fields => [qw/id name/],
sql => 'SELECT id, name FROM thing',);
- my $view1_sql2 = SQL::Translator::Producer::SQLite::create_view($view2, $create_opts);
- my $view_sql_noreplace = "CREATE VIEW view_foo AS
- SELECT id, name FROM thing";
- is($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL');
+ my $view1_sql2 = [ SQL::Translator::Producer::SQLite::create_view($view2, $create_opts) ];
+ my $view_sql_noreplace = [ "CREATE VIEW view_foo AS
+ SELECT id, name FROM thing" ];
+ is_deeply($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL');
}
);
my $create_opts = { no_comments => 1 };
my $view1_sql1 =
- SQL::Translator::Producer::SQLite::create_view( $view1, $create_opts );
+ [ SQL::Translator::Producer::SQLite::create_view( $view1, $create_opts ) ];
- my $view_sql_replace = "CREATE TEMPORARY VIEW IF NOT EXISTS view_foo AS
- SELECT id, name FROM thing";
- is( $view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL' );
+ my $view_sql_replace = [ "CREATE TEMPORARY VIEW IF NOT EXISTS view_foo AS
+ SELECT id, name FROM thing" ];
+ is_deeply( $view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL' );
my $view2 = SQL::Translator::Schema::View->new(
name => 'view_foo',
);
my $view1_sql2 =
- SQL::Translator::Producer::SQLite::create_view( $view2, $create_opts );
- my $view_sql_noreplace = "CREATE VIEW view_foo AS
- SELECT id, name FROM thing";
- is( $view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL' );
+ [ SQL::Translator::Producer::SQLite::create_view( $view2, $create_opts ) ];
+ my $view_sql_noreplace = [ "CREATE VIEW view_foo AS
+ SELECT id, name FROM thing" ];
+ is_deeply( $view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL' );
}