use SQL::Translator::Generator::DDL::SQLite;
our ( $DEBUG, $WARN );
-our $VERSION = '1.59';
+our $VERSION = '1.62';
$DEBUG = 0 unless defined $DEBUG;
$WARN = 0 unless defined $WARN;
local $NO_QUOTES = 0
if $translator->quote_identifiers and $translator->quote_identifiers ne '0E0';
- my $head = (header_comment() . "\n") unless $no_comments;
+ my $head;
+ $head = (header_comment() . "\n") unless $no_comments;
my @create = ();
if ($c->type eq "FOREIGN KEY") {
push @field_defs, create_foreignkey($c);
}
+ elsif ($c->type eq "CHECK") {
+ push @field_defs, create_check_constraint($c);
+ }
next unless $c->type eq UNIQUE;
push @constraint_defs, create_constraint($c);
}
return (@create, $create_table, @index_defs, @constraint_defs );
}
+sub create_check_constraint {
+ my $c = shift;
+ my $check = '';
+ $check .= 'CONSTRAINT ' . _generator->quote( $c->name ) . ' ' if $c->name;
+ $check .= 'CHECK(' . $c->expression . ')';
+ return $check;
+}
+
sub create_foreignkey {
my $c = shift;
$DB::single = 1;
my $action = "";
if (not ref $trigger->action) {
- $action .= "BEGIN " . $trigger->action . " END";
+ $action = $trigger->action;
+ $action = "BEGIN " . $action . " END"
+ unless $action =~ /^ \s* BEGIN [\s\;] .*? [\s\;] END [\s\;]* $/six;
}
else {
$action = $trigger->action->{for_each} . " "