From: Ken Youens-Clark Date: Tue, 26 Aug 2003 21:38:24 +0000 (+0000) Subject: Added drop table rule, saving of table comments. X-Git-Tag: v0.04~214 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=067e3cf4f07eceebdf080da29d95c1b57c4d17ce;p=dbsrgits%2FSQL-Translator.git Added drop table rule, saving of table comments. --- diff --git a/lib/SQL/Translator/Parser/Oracle.pm b/lib/SQL/Translator/Parser/Oracle.pm index 14415ec..be1af4a 100644 --- a/lib/SQL/Translator/Parser/Oracle.pm +++ b/lib/SQL/Translator/Parser/Oracle.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::Oracle; # ------------------------------------------------------------------- -# $Id: Oracle.pm,v 1.7 2003-08-21 02:39:21 kycl4rk Exp $ +# $Id: Oracle.pm,v 1.8 2003-08-26 21:38:24 kycl4rk Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark # @@ -95,7 +95,7 @@ constrnt_state use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -114,7 +114,7 @@ my $parser; $GRAMMAR = q! -{ my ( %tables, $table_order ) } +{ my ( %tables, $table_order, @table_comments ) } # # The "eofile" rule makes the parser fail if any "statement" rule @@ -127,13 +127,20 @@ startrule : statement(s) eofile { \%tables } eofile : /^\Z/ statement : create - | comment - | comment_on_table - | comment_on_column - | alter - | + | comment + | comment_on_table + | comment_on_column + | alter + | drop + | alter : /alter/i WORD /[^;]+/ ';' + { @table_comments = () } + +drop : /drop/i TABLE ';' + +drop : /drop/i WORD(s) ';' + { @table_comments = () } create : create_table table_name '(' create_definition(s /,/) ')' table_option(s?) ';' { @@ -141,6 +148,11 @@ create : create_table table_name '(' create_definition(s /,/) ')' table_option(s $tables{ $table_name }{'order'} = ++$table_order; $tables{ $table_name }{'table_name'} = $table_name; + if ( @table_comments ) { + $tables{ $table_name }{'comments'} = [ @table_comments ]; + @table_comments = (); + } + my $i = 1; my @constraints; for my $definition ( @{ $item[4] } ) { @@ -186,6 +198,7 @@ create : create_table table_name '(' create_definition(s /,/) ')' table_option(s # Create anything else (e.g., domain, function, etc.) create : /create/i WORD /[^;]+/ ';' + { @table_comments = () } global_temporary: /global/i /temporary/i @@ -199,6 +212,9 @@ create_definition : field | comment : /^\s*(?:#|-{2}).*\n/ + { + push @table_comments, $comment; + } comment_on_table : /comment/i /on/i /table/i table_name /is/i comment_phrase ';' { @@ -442,6 +458,8 @@ WORD : /\w+/ NAME : /\w+/ { $item[1] } +TABLE : /table/i + VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/ { $item[1] } | /'.*?'/ # XXX doesn't handle embedded quotes