From: Justin Hunter Date: Sat, 22 Aug 2009 21:22:09 +0000 (-0700) Subject: update SQLite grammar X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=feb8eab54c9676909eb70f905cb6b840f2ac3eec;p=dbsrgits%2FSQL-Translator-2.0-ish.git update SQLite grammar --- diff --git a/lib/SQL/Translator/Grammar/SQLite.pm b/lib/SQL/Translator/Grammar/SQLite.pm index e35c736..57bebdb 100644 --- a/lib/SQL/Translator/Grammar/SQLite.pm +++ b/lib/SQL/Translator/Grammar/SQLite.pm @@ -1,22 +1,5 @@ use MooseX::Declare; role SQL::Translator::Grammar::SQLite { -# ------------------------------------------------------------------- -# Copyright (C) 2002-2009 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 -# published by the Free Software Foundation; version 2. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA -# ------------------------------------------------------------------- method _build_grammar { return q! @@ -77,14 +60,14 @@ 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'}; my $index = { name => $item[5], - columns => $item[8], + fields => $item[8], on_conflict => $item[9][0], is_temporary => $item[2][0] ? 1 : 0, }; @@ -114,7 +97,7 @@ create : CREATE TEMPORARY(?) TABLE table_name '(' definition(s /,/) ')' SEMICOLO for my $def ( @{ $item[6] } ) { if ( $def->{'supertype'} eq 'column' ) { - push @{ $tables{ $table_name }{'columns'} }, $def; + push @{ $tables{ $table_name }{'fields'} }, $def; } elsif ( $def->{'supertype'} eq 'constraint' ) { push @{ $tables{ $table_name }{'constraints'} }, $def; @@ -157,6 +140,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; @@ -210,13 +196,29 @@ 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(?) { $return = { supertype => 'constraint', type => 'primary_key', - columns => $item[2], + fields => $item[2], on_conflict => $item[3][0], } } @@ -226,7 +228,7 @@ constraint_def : PRIMARY_KEY parens_field_list conflict_clause(?) $return = { supertype => 'constraint', type => 'unique', - columns => $item[2], + fields => $item[2], on_conflict => $item[3][0], } } @@ -241,6 +243,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 @@ -393,11 +398,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] }