Parsing of foreign keys.
Ken Youens-Clark [Tue, 11 Aug 2009 21:33:03 +0000 (21:33 +0000)]
lib/SQL/Translator/Parser/SQLite.pm

index 0de6e12..c1db5c4 100644 (file)
@@ -357,6 +357,15 @@ column_constraint : NOT_NULL conflict_clause(?)
             value => $item[2],
         }
     }
+    |
+    REFERENCES ref_def
+    {
+        $return   = {
+            type             => 'foreign_key',
+            reference_table  => $item[2]{'reference_table'},
+            reference_fields => $item[2]{'reference_fields'},
+        }
+    }
 
 constraint_def : PRIMARY_KEY parens_field_list conflict_clause(?)
     {
@@ -388,6 +397,9 @@ constraint_def : PRIMARY_KEY parens_field_list conflict_clause(?)
         }
     }
 
+ref_def : /(\w+)\s*\((\w+)\)/
+    { $return = { reference_table => $1, reference_fields => $2 } }
+
 table_name : qualified_name
     
 qualified_name : NAME 
@@ -540,6 +552,8 @@ WORD : /\w+/
 
 WHEN : /when/i
 
+REFERENCES : /references/i
+
 UNIQUE : /unique/i { 1 }
 
 SEMICOLON : ';'
@@ -630,8 +644,10 @@ sub parse {
                 reference_table  => $cdata->{'reference_table'},
                 reference_fields => $cdata->{'reference_fields'},
                 match_type       => $cdata->{'match_type'} || '',
-                on_delete        => $cdata->{'on_delete'} || $cdata->{'on_delete_do'},
-                on_update        => $cdata->{'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;
         }
     }
@@ -667,7 +683,7 @@ sub parse {
 
 =head1 AUTHOR
 
-Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
+Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
 
 =head1 SEE ALSO