Skip to content

Commit 66b7dc7

Browse files
committed
sqlite: output view fields in SQL
1 parent 18be6d1 commit 66b7dc7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/SQL/Translator/Producer/SQLite.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ sub create_view {
158158
if exists($extra->{if_not_exists}) && $extra->{if_not_exists};
159159
$create_view .= " ${view_name}";
160160

161+
if (my @fields = $view->fields) {
162+
my $field_list = join ', ', map { _generator->quote($_) } @fields;
163+
$create_view .= " ( ${field_list} )";
164+
}
165+
161166
if (my $sql = $view->sql) {
162167
$create_view .= " AS\n ${sql}";
163168
}

t/56-sqlite-producer.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $SQL::Translator::Producer::SQLite::NO_QUOTES = 0;
2525
my $view1_sql1 = [ SQL::Translator::Producer::SQLite::create_view($view1, $create_opts) ];
2626

2727
my $view_sql_replace = [
28-
'CREATE TEMPORARY VIEW IF NOT EXISTS "view_foo" AS
28+
'CREATE TEMPORARY VIEW IF NOT EXISTS "view_foo" ( "id", "name" ) AS
2929
SELECT id, name FROM thing'
3030
];
3131
is_deeply($view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL');
@@ -38,7 +38,7 @@ $SQL::Translator::Producer::SQLite::NO_QUOTES = 0;
3838

3939
my $view1_sql2 = [ SQL::Translator::Producer::SQLite::create_view($view2, $create_opts) ];
4040
my $view_sql_noreplace = [
41-
'CREATE VIEW "view_foo" AS
41+
'CREATE VIEW "view_foo" ( "id", "name" ) AS
4242
SELECT id, name FROM thing'
4343
];
4444
is_deeply($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL');

0 commit comments

Comments
 (0)