From: Ash Berlin Date: Sat, 7 Feb 2009 17:50:03 +0000 (+0000) Subject: Fix tests! X-Git-Tag: v0.11008~243 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f9c96971577d9e276783e98920b3c6346f24f20e;p=dbsrgits%2FSQL-Translator.git Fix tests! --- diff --git a/lib/SQL/Translator/Diff.pm b/lib/SQL/Translator/Diff.pm index 99de6b7..dae513a 100644 --- a/lib/SQL/Translator/Diff.pm +++ b/lib/SQL/Translator/Diff.pm @@ -228,6 +228,7 @@ sub produce_diff_sql { # TODO: sort out options %{ $self->producer_options } ); + $translator->producer_args->{no_transaction} = 1; my $schema = $translator->schema; $schema->add_table($_) for @tables; diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index 1e236d4..b2a2675 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -195,7 +195,7 @@ statement : begin_transaction | create | -begin_transaction : /begin transaction/i SEMICOLON +begin_transaction : /begin/i TRANSACTION(?) SEMICOLON commit : /commit/i SEMICOLON @@ -497,6 +497,8 @@ BEGIN_C : /begin/i END_C : /end/i +TRANSACTION: /transaction/i + CREATE : /create/i TEMPORARY : /temp(orary)?/i { 1 } diff --git a/lib/SQL/Translator/Producer/HTML.pm b/lib/SQL/Translator/Producer/HTML.pm index 14ab7d5..8936f65 100644 --- a/lib/SQL/Translator/Producer/HTML.pm +++ b/lib/SQL/Translator/Producer/HTML.pm @@ -24,7 +24,7 @@ use strict; use Data::Dumper; use vars qw($NOWRAP $NOLINKTABLE $NAME); -$NAME = join ', ', __PACKAGE__, $VERSION; +$NAME = __PACKAGE__; $NOWRAP = 0 unless defined $NOWRAP; $NOLINKTABLE = 0 unless defined $NOLINKTABLE; diff --git a/lib/SQL/Translator/Producer/SQLite.pm b/lib/SQL/Translator/Producer/SQLite.pm index 9eeeaa3..1c6b610 100644 --- a/lib/SQL/Translator/Producer/SQLite.pm +++ b/lib/SQL/Translator/Producer/SQLite.pm @@ -61,13 +61,14 @@ sub produce { my $add_drop_table = $translator->add_drop_table; my $schema = $translator->schema; my $producer_args = $translator->producer_args; - my $sqlite_version = $producer_args->{sqlite_version} || 0; + my $sqlite_version = $producer_args->{sqlite_version} || 0; + my $no_txn = $producer_args->{no_transaction}; debug("PKG: Beginning production\n"); my @create = (); push @create, header_comment unless ($no_comments); - $create[0] .= "\n\nBEGIN TRANSACTION"; + $create[0] .= "\n\nBEGIN TRANSACTION" unless $no_txn; for my $table ( $schema->get_tables ) { push @create, create_table($table, { no_comments => $no_comments, @@ -89,7 +90,13 @@ sub produce { }); } - return wantarray ? (@create, "COMMIT") : join(";\n\n", (@create, "COMMIT;\n")); + if (wantarray) { + push @create, "COMMIT" unless $no_txn; + return @create; + } else { + push @create, "COMMIT;\n" unless $no_txn; + return join(";\n\n", @create ); + } } # ------------------------------------------------------------------- @@ -368,20 +375,25 @@ sub create_trigger { die "Can't handle multiple events in triggers" if @$events > 1; my $action = ""; - - $action = $trigger->ation->{for_each} . " " - if $trigger->action->{for_each}; - $action = $trigger->action->{when} . " " - if $trigger->action->{when}; + $DB::single = 1; + unless (ref $trigger->action) { + $action .= "BEGIN " . $trigger->action . " END"; + } else { + $action = $trigger->action->{for_each} . " " + if $trigger->action->{for_each}; - my $steps = $trigger->action->{steps} || []; + $action = $trigger->action->{when} . " " + if $trigger->action->{when}; - $action .= "BEGIN "; - for (@$steps) { - $action .= $_ . "; " + my $steps = $trigger->action->{steps} || []; + + $action .= "BEGIN "; + for (@$steps) { + $action .= $_ . "; " + } + $action .= "END"; } - $action .= "END"; push @create, "CREATE TRIGGER $name " . $trigger->perform_action_when . " " . diff --git a/t/13schema.t b/t/13schema.t index 8a23b44..7770939 100644 --- a/t/13schema.t +++ b/t/13schema.t @@ -590,7 +590,7 @@ require_ok( 'SQL::Translator::Schema' ); my $t = $s->add_trigger( name => $name, perform_action_when => $perform_action_when, - database_event => $database_event, + database_events => [$database_event], on_table => $on_table, action => $action, ) or die $s->error; @@ -601,7 +601,7 @@ require_ok( 'SQL::Translator::Schema' ); is( $t->name, $name, qq[Name is "$name"] ); is( $t->perform_action_when, $perform_action_when, qq[Perform action when is "$perform_action_when"] ); - is( $t->database_event, $database_event, + is( $t->database_events->[0], $database_event, qq[Database event is "$database_event"] ); isa_ok( $t->table, 'SQL::Translator::Schema::Table', qq[table is a Table"] ); is( $t->action, $action, qq[Action is "$action"] ); diff --git a/t/17sqlfxml-producer.t b/t/17sqlfxml-producer.t index 31bbf0c..af4b08c 100644 --- a/t/17sqlfxml-producer.t +++ b/t/17sqlfxml-producer.t @@ -208,7 +208,7 @@ EOXML my $t = $s->add_trigger( name => $name, perform_action_when => $perform_action_when, - database_event => $database_event, + database_events => [$database_event], table => $table, action => $action, extra => { hello => "world" }, diff --git a/t/29html.t b/t/29html.t index f1f48fc..a4cc607 100644 --- a/t/29html.t +++ b/t/29html.t @@ -31,13 +31,14 @@ CREATE TABLE foo ( |; my $tr = SQL::Translator->new(parser => 'MySQL', producer => 'HTML'); -my $parsed = $tr->translate(data => $create); +my $parsed = $tr->translate(data => $create) or die $tr->error; my $status; eval { $status = $p->parse($parsed); }; if ($@) { + daig $@; fail("Unable to parse the output!"); } diff --git a/t/48xml-to-sqlite.t b/t/48xml-to-sqlite.t index 7b92f76..c1dba06 100644 --- a/t/48xml-to-sqlite.t +++ b/t/48xml-to-sqlite.t @@ -34,6 +34,8 @@ my $sql = $sqlt->translate( ) or die $sqlt->error; eq_or_diff($sql, << "SQL"); + + BEGIN TRANSACTION; DROP TABLE Basic; @@ -65,6 +67,10 @@ 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; + COMMIT; SQL @@ -75,9 +81,9 @@ my @sql = $sqlt->translate( filename => $xmlfile, ) or die $sqlt->error; -is_deeply(\@sql, +eq_or_diff(\@sql, [ - 'BEGIN TRANSACTION', + "\n\nBEGIN TRANSACTION", 'DROP TABLE Basic', 'CREATE TABLE Basic ( id INTEGER PRIMARY KEY NOT NULL, @@ -100,6 +106,8 @@ is_deeply(\@sql, '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', 'COMMIT' ], 'SQLite translate in list context matches');