5 use Test::More tests => 3;
6 use Test::SQL::Translator qw(maybe_plan);
9 use SQL::Translator::Schema::View;
10 use SQL::Translator::Schema::Table;
11 use SQL::Translator::Producer::SQLite;
12 $SQL::Translator::Producer::SQLite::NO_QUOTES = 0;
15 my $view1 = SQL::Translator::Schema::View->new( name => 'view_foo',
16 fields => [qw/id name/],
17 sql => 'SELECT id, name FROM thing',
22 my $create_opts = { no_comments => 1 };
23 my $view1_sql1 = [ SQL::Translator::Producer::SQLite::create_view($view1, $create_opts) ];
25 my $view_sql_replace = [ 'CREATE TEMPORARY VIEW IF NOT EXISTS "view_foo" AS
26 SELECT id, name FROM thing' ];
27 is_deeply($view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL');
30 my $view2 = SQL::Translator::Schema::View->new( name => 'view_foo',
31 fields => [qw/id name/],
32 sql => 'SELECT id, name FROM thing',);
34 my $view1_sql2 = [ SQL::Translator::Producer::SQLite::create_view($view2, $create_opts) ];
35 my $view_sql_noreplace = [ 'CREATE VIEW "view_foo" AS
36 SELECT id, name FROM thing' ];
37 is_deeply($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL');
42 my $table = SQL::Translator::Schema::Table->new(
46 name => 'foreign_key',
47 data_type => 'integer',
49 my $constraint = SQL::Translator::Schema::Constraint->new(
52 type => 'FOREIGN_KEY',
53 fields => ['foreign_key'],
54 reference_fields => ['id'],
55 reference_table => 'foo',
56 on_delete => 'RESTRICT',
57 on_update => 'CASCADE',
60 my $expected = [ 'FOREIGN KEY ("foreign_key") REFERENCES "foo"("id") ON DELETE RESTRICT ON UPDATE CASCADE'];
61 my $result = [SQL::Translator::Producer::SQLite::create_foreignkey($constraint,$create_opts)];
62 is_deeply($result, $expected, 'correct "FOREIGN KEY"');