From: Ken Youens-Clark Date: Tue, 11 Aug 2009 21:33:03 +0000 (+0000) Subject: Parsing of foreign keys. X-Git-Tag: v0.11008~127 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=08e01b5c174510eb5c21f9a981273f130c5cd02c;p=dbsrgits%2FSQL-Translator.git Parsing of foreign keys. --- diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index 0de6e12..c1db5c4 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -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 Ekclark@cpan.orgE. +Ken Youens-Clark Ekclark@cpan.orgE. =head1 SEE ALSO