X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FSQLite.pm;h=01880283b590cc92e67c41be5f036b2c699ca78b;hb=56b9e6a566b09e57d63d8b854f80f84002ae0f14;hp=c1db5c44d26e25aa104d33a47cfe3b2cb12b6bfc;hpb=08e01b5c174510eb5c21f9a981273f130c5cd02c;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index c1db5c4..0188028 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -224,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'}; @@ -271,7 +271,7 @@ create : CREATE TEMPORARY(?) TABLE table_name '(' definition(s /,/) ')' SEMICOLO definition : constraint_def | column_def -column_def: comment(s?) NAME type(?) column_constraint(s?) +column_def: comment(s?) NAME type(?) column_constraint_def(s?) { my $column = { supertype => 'column', @@ -304,6 +304,9 @@ column_def: comment(s?) 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; @@ -317,6 +320,16 @@ type : WORD parens_value_list(?) } } +column_constraint_def : CONSTRAINT constraint_name column_constraint + { + $return = { + name => $item[2], + %{ $item[3] }, + } + } + | + column_constraint + column_constraint : NOT_NULL conflict_clause(?) { $return = { @@ -366,8 +379,32 @@ column_constraint : NOT_NULL conflict_clause(?) reference_fields => $item[2]{'reference_fields'}, } } + | + AUTOINCREMENT + { + $return = { + type => 'autoincrement', + } + } -constraint_def : PRIMARY_KEY parens_field_list conflict_clause(?) +constraint_def : comment(s?) CONSTRAINT constraint_name table_constraint + { + $return = { + comments => $item[1], + name => $item[3], + %{ $item[4] }, + } + } + | + comment(s?) table_constraint + { + $return = { + comments => $item[1], + %{ $item[2] }, + } + } + +table_constraint : PRIMARY_KEY parens_field_list conflict_clause(?) { $return = { supertype => 'constraint', @@ -410,6 +447,8 @@ qualified_name : /(\w+)\.(\w+)/ field_name : NAME +constraint_name : NAME + conflict_clause : /on conflict/i conflict_algorigthm conflict_algorigthm : /(rollback|abort|fail|ignore|replace)/i @@ -554,11 +593,15 @@ WHEN : /when/i REFERENCES : /references/i +CONSTRAINT : /constraint/i + +AUTOINCREMENT : /autoincrement/i + UNIQUE : /unique/i { 1 } SEMICOLON : ';' -NAME : /'?(\w+)'?/ { $return = $1 } +NAME : /["']?(\w+)["']?/ { $return = $1 } VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/ { $item[1] } @@ -631,7 +674,7 @@ sub parse { for my $idata ( @{ $tdata->{'indices'} || [] } ) { my $index = $table->add_index( name => $idata->{'name'}, - type => uc $idata->{'type'}, + type => uc ($idata->{'type'}||''), fields => $idata->{'fields'}, ) or die $table->error; }