Only output trigger 'scope' if it's set in YAML and JSON producers
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / SQLite.pm
index 1c04edd..9cc92af 100644 (file)
@@ -236,6 +236,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 +248,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 +352,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 +383,7 @@ sub create_trigger {
   return @statements;
 }
 
-sub alter_table { } # Noop
+sub alter_table { () } # Noop
 
 sub add_field {
   my ($field) = @_;