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!
#
# 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,
};
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;
elsif ( $c->{'type'} eq 'default' ) {
$column->{'default'} = $c->{'value'};
}
+ elsif ( $c->{'type'} eq 'autoincrement' ) {
+ $column->{'is_auto_inc'} = 1;
+ }
}
$column;
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],
}
}
$return = {
supertype => 'constraint',
type => 'unique',
- columns => $item[2],
+ fields => $item[2],
on_conflict => $item[3][0],
}
}
}
}
+ref_def : /(\w+)\s*\((\w+)\)/
+ { $return = { reference_table => $1, reference_fields => $2 } }
+
table_name : qualified_name
qualified_name : NAME
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] }