X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F56-sqlite-producer.t;h=752559db147094fe746a9c9d1e7dd2d89311065b;hb=ea4a3ecc5de1c8f062fef3bab51e1cc7a2c23235;hp=945a8bda86f39580b069a426e14d2fb17762a668;hpb=4c0d31c125be1c212c2b984f4a4d806a61b2bd6e;p=dbsrgits%2FSQL-Translator.git diff --git a/t/56-sqlite-producer.t b/t/56-sqlite-producer.t index 945a8bd..752559d 100644 --- a/t/56-sqlite-producer.t +++ b/t/56-sqlite-producer.t @@ -2,11 +2,12 @@ # vim: set ft=perl: use strict; -use Test::More tests => 2; +use Test::More tests => 3; use Test::SQL::Translator qw(maybe_plan); use FindBin qw/$Bin/; use SQL::Translator::Schema::View; +use SQL::Translator::Schema::Table; use SQL::Translator::Producer::SQLite; { @@ -20,7 +21,7 @@ use SQL::Translator::Producer::SQLite; my $create_opts = { no_comments => 1 }; 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 + 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'); @@ -30,7 +31,32 @@ use SQL::Translator::Producer::SQLite; 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 + 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; + + my $table = SQL::Translator::Schema::Table->new( + name => 'foo_table', + ); + $table->add_field( + name => 'foreign_key', + data_type => 'integer', + ); + my $constraint = SQL::Translator::Schema::Constraint->new( + table => $table, + name => 'fk', + type => 'FOREIGN_KEY', + fields => ['foreign_key'], + reference_fields => ['id'], + reference_table => 'foo', + on_delete => 'RESTRICT', + on_update => 'CASCADE', + ); + + my $expected = [ "FOREIGN KEY ('foreign_key') REFERENCES 'foo'('id') ON DELETE RESTRICT ON UPDATE CASCADE"]; + my $result = [SQL::Translator::Producer::SQLite::create_foreignkey($constraint,$create_opts)]; + is_deeply($result, $expected, 'correct "FOREIGN KEY"'); +}