X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FSQLite.pm;h=c4c2fe168029bb48ead765d13f5acf7f169334d9;hb=11ad2df91bcc0674faa8fb5b6bab52c9e4a73762;hp=fe15bf4317d266322d75de62c891b9b96cb2be6a;hpb=da06ac74ada30aacf656943306679a28605ad5c8;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index fe15bf4..c4c2fe1 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -1,8 +1,6 @@ package SQL::Translator::Parser::SQLite; # ------------------------------------------------------------------- -# $Id: SQLite.pm 1445 2009-02-07 17:50:03Z ashberlin $ -# ------------------------------------------------------------------- # Copyright (C) 2002-2009 SQLFairy Authors # # This program is free software; you can redistribute it and/or @@ -152,7 +150,7 @@ like-op::= use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = '1.99'; +$VERSION = '1.59'; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -200,7 +198,13 @@ begin_transaction : /begin/i TRANSACTION(?) SEMICOLON commit : /commit/i SEMICOLON -drop : /drop/i TABLE table_name SEMICOLON +drop : /drop/i (tbl_drop | view_drop | trg_drop) SEMICOLON + +tbl_drop: TABLE table_name + +view_drop: VIEW if_exists(?) view_name + +trg_drop: TRIGGER if_exists(?) trigger_name comment : /^\s*(?:#|-{2}).*\n/ { @@ -220,7 +224,7 @@ comment : /\/\*/ /[^\*]+/ /\*\// # # Create Index # -create : CREATE TEMPORARY(?) UNIQUE(?) INDEX WORD ON table_name parens_field_list conflict_clause(?) SEMICOLON +create : CREATE TEMPORARY(?) UNIQUE(?) INDEX NAME ON table_name parens_field_list conflict_clause(?) SEMICOLON { my $db_name = $item[7]->{'db_name'} || ''; my $table_name = $item[7]->{'name'}; @@ -267,22 +271,24 @@ create : CREATE TEMPORARY(?) TABLE table_name '(' definition(s /,/) ')' SEMICOLO definition : constraint_def | column_def -column_def: NAME type(?) column_constraint(s?) +column_def: comment(s?) NAME type(?) column_constraint(s?) { my $column = { supertype => 'column', - name => $item[1], - data_type => $item[2][0]->{'type'}, - size => $item[2][0]->{'size'}, + name => $item[2], + data_type => $item[3][0]->{'type'}, + size => $item[3][0]->{'size'}, is_nullable => 1, is_primary_key => 0, is_unique => 0, check => '', default => undef, - constraints => $item[3], + constraints => $item[4], + comments => $item[1], }; - for my $c ( @{ $item[3] } ) { + + for my $c ( @{ $item[4] } ) { if ( $c->{'type'} eq 'not_null' ) { $column->{'is_nullable'} = 0; } @@ -298,6 +304,9 @@ column_def: NAME type(?) column_constraint(s?) elsif ( $c->{'type'} eq 'default' ) { $column->{'default'} = $c->{'value'}; } + elsif ( $c->{'type'} eq 'autoincrement' ) { + $column->{'is_auto_inc'} = 1; + } } $column; @@ -351,6 +360,22 @@ 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'}, + } + } + | + AUTOINCREMENT + { + $return = { + type => 'autoincrement', + } + } constraint_def : PRIMARY_KEY parens_field_list conflict_clause(?) { @@ -382,6 +407,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 @@ -461,9 +489,9 @@ string : nonstring : /[^;\'"]+/ -statement_body : (string | nonstring)(s?) +statement_body : string | nonstring -trigger_step : /(select|delete|insert|update)/i statement_body SEMICOLON +trigger_step : /(select|delete|insert|update)/i statement_body(s?) SEMICOLON { $return = join( ' ', $item[1], join ' ', @{ $item[2] || [] } ) } @@ -472,8 +500,12 @@ before_or_after : /(before|after)/i { $return = lc $1 } instead_of : /instead of/i +if_exists : /if exists/i + view_name : qualified_name +trigger_name : qualified_name + # # Create View # @@ -530,11 +562,15 @@ WORD : /\w+/ WHEN : /when/i +REFERENCES : /references/i + +AUTOINCREMENT : /autoincrement/i + UNIQUE : /unique/i { 1 } SEMICOLON : ';' -NAME : /'?(\w+)'?/ { $return = $1 } +NAME : /["']?(\w+)["']?/ { $return = $1 } VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/ { $item[1] } @@ -620,8 +656,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; } } @@ -657,7 +695,7 @@ sub parse { =head1 AUTHOR -Ken Y. Clark Ekclark@cpan.orgE. +Ken Youens-Clark Ekclark@cpan.orgE. =head1 SEE ALSO