X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer%2FSQLite.pm;h=ffbbbe077143908384ff79eb678540677a34930f;hb=1f742579d2d66e83f3f36c22e60acb5f4930e025;hp=1c04edde3d7c018ffbb0cbecada153dd8c0f82c6;hpb=2491a467cb7f1991af6aa89d09e7bfd974583242;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer/SQLite.pm b/lib/SQL/Translator/Producer/SQLite.pm index 1c04edd..ffbbbe0 100644 --- a/lib/SQL/Translator/Producer/SQLite.pm +++ b/lib/SQL/Translator/Producer/SQLite.pm @@ -66,7 +66,8 @@ sub produce { 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 = (); @@ -236,6 +237,9 @@ sub create_table 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); } @@ -245,6 +249,14 @@ sub create_table 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; @@ -341,7 +353,9 @@ sub create_trigger { $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} . " " @@ -370,7 +384,7 @@ sub create_trigger { return @statements; } -sub alter_table { } # Noop +sub alter_table { () } # Noop sub add_field { my ($field) = @_;