# TODO: sort out options
%{ $self->producer_options }
);
+ $translator->producer_args->{no_transaction} = 1;
my $schema = $translator->schema;
$schema->add_table($_) for @tables;
| create
| <error>
-begin_transaction : /begin transaction/i SEMICOLON
+begin_transaction : /begin/i TRANSACTION(?) SEMICOLON
commit : /commit/i SEMICOLON
END_C : /end/i
+TRANSACTION: /transaction/i
+
CREATE : /create/i
TEMPORARY : /temp(orary)?/i { 1 }
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;
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,
});
}
- 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 );
+ }
}
# -------------------------------------------------------------------
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 . " " .
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;
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"] );
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" },
|;
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!");
}
) or die $sqlt->error;
eq_or_diff($sql, << "SQL");
+
+
BEGIN TRANSACTION;
DROP TABLE Basic;
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
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,
'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');