diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index 1aab7f077..d61889d16 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -147,7 +147,7 @@ our @EXPORT_OK = qw(parse); our $GRAMMAR = <<'END_OF_GRAMMAR'; { - my ( %tables, $table_order, @table_comments, @views, @triggers ); + my ( %tables, $table_order, @views, @triggers ); sub _err { my $max_lines = 5; @@ -179,8 +179,8 @@ eofile : /^\Z/ statement : begin_transaction | commit | drop - | comment | create + | comment | /^\Z/ | { _err ($thisline, $text) } begin_transaction : /begin/i TRANSACTION(?) SEMICOLON @@ -239,16 +239,17 @@ create : CREATE TEMPORARY(?) UNIQUE(?) INDEX NAME ON table_name parens_field_lis # # Create Table # -create : CREATE TEMPORARY(?) TABLE table_name '(' definition(s /,/) ')' SEMICOLON +create : comment(s?) CREATE TEMPORARY(?) TABLE table_name '(' definition(s /,/) ')' SEMICOLON { - my $db_name = $item[4]->{'db_name'} || ''; - my $table_name = $item[4]->{'name'}; + my $db_name = $item[5]->{'db_name'} || ''; + my $table_name = $item[5]->{'name'}; $tables{ $table_name }{'name'} = $table_name; - $tables{ $table_name }{'is_temporary'} = $item[2][0] ? 1 : 0; + $tables{ $table_name }{'is_temporary'} = $item[3][0] ? 1 : 0; + $tables{ $table_name }{'comments'} = $item[1]; $tables{ $table_name }{'order'} = ++$table_order; - for my $def ( @{ $item[6] } ) { + for my $def ( @{ $item[7] } ) { if ( $def->{'supertype'} eq 'column' ) { push @{ $tables{ $table_name }{'fields'} }, $def; } diff --git a/t/23json.t b/t/23json.t index 431ce4dc1..9612a77fc 100644 --- a/t/23json.t +++ b/t/23json.t @@ -137,7 +137,12 @@ my $json = from_json(<import('parse'); @@ -31,6 +31,12 @@ my $file = "$Bin/data/sqlite/create.sql"; my $t1 = shift @tables; is( $t1->name, 'person', "'Person' table" ); + is_deeply( [ $t1->comments ], + [ q(table comment 1), + q(table comment 2), + q(table comment 3) + ], + 'person table comments' ); my @fields = $t1->get_fields; is( scalar @fields, 6, 'Six fields in "person" table'); diff --git a/t/data/sqlite/create.sql b/t/data/sqlite/create.sql index 56f115313..ccabe41bc 100644 --- a/t/data/sqlite/create.sql +++ b/t/data/sqlite/create.sql @@ -1,3 +1,6 @@ +-- table comment 1 +-- table comment 2 +-- table comment 3 create table person ( -- field comment 1 -- field comment 2