Typo fixing
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / SQLite.pm
index 2f81efe..996935a 100644 (file)
@@ -1,11 +1,9 @@
 package SQL::Translator::Parser::SQLite;
 
 # -------------------------------------------------------------------
-# $Id: SQLite.pm,v 1.2 2003-10-04 01:16:39 kycl4rk Exp $
+# $Id: SQLite.pm,v 1.8 2006-06-07 16:08:45 schiffbruechige Exp $
 # -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
-#                    darren chamberlain <darren@cpan.org>,
-#                    Chris Mungall <cjm@fruitfly.org>
+# Copyright (C) 2002-4 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -111,7 +109,7 @@ trigger-action ::=
 
 trigger-step ::=
     update-statement | insert-statement | 
-    delete-statement | select-statemen
+    delete-statement | select-statement
 
 CREATE VIEW
 
@@ -154,7 +152,7 @@ like-op::=
 
 use strict;
 use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/;
 $DEBUG   = 0 unless defined $DEBUG;
 
 use Data::Dumper;
@@ -182,7 +180,7 @@ $GRAMMAR = q!
 # failed. -ky
 #
 startrule : statement(s) eofile { 
-    $return      => {
+    $return      = {
         tables   => \%tables, 
         views    => \@views,
         triggers => \@triggers,
@@ -193,6 +191,7 @@ eofile : /^\Z/
 
 statement : begin_transaction
     | commit
+    | drop
     | comment
     | create
     | <error>
@@ -201,6 +200,8 @@ begin_transaction : /begin transaction/i SEMICOLON
 
 commit : /commit/i SEMICOLON
 
+drop : /drop/i TABLE <commit> table_name SEMICOLON
+
 comment : /^\s*(?:#|-{2}).*\n/
     {
         my $comment =  $item[1];
@@ -535,6 +536,8 @@ VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/
     }
     | /NULL/
     { 'NULL' }
+    | /CURRENT_TIMESTAMP/i
+    { 'CURRENT_TIMESTAMP' }
 
 !;
 
@@ -556,9 +559,11 @@ sub parse {
     warn Dumper( $result ) if $DEBUG;
 
     my $schema = $translator->schema;
-    my @tables = sort { 
-        $result->{ $a }->{'order'} <=> $result->{ $b }->{'order'}
-    } keys %{ $result->{'tables'} };
+    my @tables = 
+        map   { $_->[1] }
+        sort  { $a->[0] <=> $b->[0] } 
+        map   { [ $result->{'tables'}{ $_ }->{'order'}, $_ ] }
+        keys %{ $result->{'tables'} };
 
     for my $table_name ( @tables ) {
         my $tdata =  $result->{'tables'}{ $table_name };
@@ -604,8 +609,8 @@ sub parse {
                 reference_table  => $cdata->{'reference_table'},
                 reference_fields => $cdata->{'reference_fields'},
                 match_type       => $cdata->{'match_type'} || '',
-                on_delete        => $cdata->{'on_delete_do'},
-                on_update        => $cdata->{'on_update_do'},
+                on_delete        => $cdata->{'on_delete'} || $cdata->{'on_delete_do'},
+                on_update        => $cdata->{'on_update'} || $cdata->{'on_update_do'},
             ) or die $table->error;
         }
     }