=head1 DESCRIPTION
-This is a grammar for parsing CREATE statements for SQLite as
+This is a grammar for parsing CREATE statements for SQLite as
described here:
http://www.sqlite.org/lang.html
CREATE INDEX
sql-statement ::=
- CREATE [TEMP | TEMPORARY] [UNIQUE] INDEX index-name
+ CREATE [TEMP | TEMPORARY] [UNIQUE] INDEX index-name
ON [database-name .] table-name ( column-name [, column-name]* )
[ ON CONFLICT conflict-algorithm ]
trigger-action
database-event ::=
- DELETE |
- INSERT |
- UPDATE |
+ DELETE |
+ INSERT |
+ UPDATE |
UPDATE OF column-list
trigger-action ::=
- [ FOR EACH ROW | FOR EACH STATEMENT ] [ WHEN expression ]
- BEGIN
+ [ FOR EACH ROW | FOR EACH STATEMENT ] [ WHEN expression ]
+ BEGIN
trigger-step ; [ trigger-step ; ]*
END
trigger-step ::=
- update-statement | insert-statement |
+ update-statement | insert-statement |
delete-statement | select-statement
CREATE VIEW
$GRAMMAR = q!
-{
+{
my ( %tables, $table_order, @table_comments, @views, @triggers );
}
#
# The "eofile" rule makes the parser fail if any "statement" rule
-# fails. Otherwise, the first successful match by a "statement"
+# fails. Otherwise, the first successful match by a "statement"
# won't cause the failure needed to know that the parse, as a whole,
# failed. -ky
#
-startrule : statement(s) eofile {
+startrule : statement(s) eofile {
$return = {
- tables => \%tables,
+ tables => \%tables,
views => \@views,
triggers => \@triggers,
}
$return = $comment;
}
-comment : /\/\*/ /[^\*]+/ /\*\//
+comment : /\/\*/ /[^\*]+/ /\*\//
{
my $comment = $item[2];
$comment =~ s/^\s*|\s*$//g;
my $db_name = $item[7]->{'db_name'} || '';
my $table_name = $item[7]->{'name'};
- my $index = {
+ my $index = {
name => $item[5],
fields => $item[8],
on_conflict => $item[9][0],
}
}
-definition : constraint_def | column_def
+definition : constraint_def | column_def
column_def: comment(s?) NAME type(?) column_constraint_def(s?)
{
$return = {
type => 'primary_key',
sort_order => $item[2][0],
- on_conflict => $item[2][0],
+ on_conflict => $item[2][0],
}
}
|
{
$return = {
type => 'unique',
- on_conflict => $item[2][0],
+ on_conflict => $item[2][0],
}
}
|
$return = {
type => 'check',
expression => $item[3],
- on_conflict => $item[5][0],
+ on_conflict => $item[5][0],
}
}
|
{ $return = { reference_table => $1, reference_fields => $2 } }
table_name : qualified_name
-
-qualified_name : NAME
+
+qualified_name : NAME
{ $return = { name => $item[1] } }
-qualified_name : /(\w+)\.(\w+)/
+qualified_name : /(\w+)\.(\w+)/
{ $return = { db_name => $1, name => $2 } }
field_name : NAME
when : WHEN expr { $item[2] }
string :
- /'(\\.|''|[^\\\'])*'/
+ /'(\\.|''|[^\\\'])*'/
nonstring : /[^;\'"]+/
trigger_step : /(select|delete|insert|update)/i statement_body(s?) SEMICOLON
{
$return = join( ' ', $item[1], join ' ', @{ $item[2] || [] } )
- }
+ }
before_or_after : /(before|after)/i { $return = lc $1 }
#
# Create View
#
-create : CREATE TEMPORARY(?) VIEW view_name AS select_statement
+create : CREATE TEMPORARY(?) VIEW view_name AS select_statement
{
push @views, {
name => $item[4]->{'name'},
- sql => $item[6],
+ sql => $item[6],
is_temporary => $item[2][0] ? 1 : 0,
}
}
VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/
{ $item[1] }
- | /'.*?'/
- {
- # remove leading/trailing quotes
+ | /'.*?'/
+ {
+ # remove leading/trailing quotes
my $val = $item[1];
$val =~ s/^['"]|['"]$//g;
$return = $val;
warn Dumper( $result ) if $DEBUG;
my $schema = $translator->schema;
- my @tables =
+ my @tables =
map { $_->[1] }
- sort { $a->[0] <=> $b->[0] }
+ sort { $a->[0] <=> $b->[0] }
map { [ $result->{'tables'}{ $_ }->{'order'}, $_ ] }
keys %{ $result->{'tables'} };
for my $table_name ( @tables ) {
my $tdata = $result->{'tables'}{ $table_name };
- my $table = $schema->add_table(
+ my $table = $schema->add_table(
name => $tdata->{'name'},
) or die $schema->error;
reference_table => $cdata->{'reference_table'},
reference_fields => $cdata->{'reference_fields'},
match_type => $cdata->{'match_type'} || '',
- on_delete => $cdata->{'on_delete'}
+ on_delete => $cdata->{'on_delete'}
|| $cdata->{'on_delete_do'},
- on_update => $cdata->{'on_update'}
+ on_update => $cdata->{'on_update'}
|| $cdata->{'on_update_do'},
) or die $table->error;
}