From: Justin Hunter Date: Sun, 23 Aug 2009 07:08:28 +0000 (-0700) Subject: cleanup and standardization X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf2a7e53c7e36eca8e6582f450360bf265ee67a5;p=dbsrgits%2FSQL-Translator-2.0-ish.git cleanup and standardization --- diff --git a/lib/SQL/Translator/Parser/DDL/MySQL.pm b/lib/SQL/Translator/Parser/DDL/MySQL.pm index 2a2134e..574aa5e 100644 --- a/lib/SQL/Translator/Parser/DDL/MySQL.pm +++ b/lib/SQL/Translator/Parser/DDL/MySQL.pm @@ -18,19 +18,11 @@ role SQL::Translator::Parser::DDL::MySQL { return $data_type_mapping; }; - multi method parse(Str $data) { - my $DEBUG = 0; - -# unless ($data) { -# open DUMP_FILE, $self->filename; -# my $data = do { local $/; ; }; -# close DUMP_FILE; -# } + multi method parse(Schema $data) { $data } + multi method parse(Str $data) { my $parser = Parse::RecDescent->new($self->grammar); -# local $::RD_TRACE = undef; #$self->trace ? 1 : undef; - unless (defined $parser) { return $self->error("Error instantiating Parse::RecDescent ". "instance: Bad grammar"); @@ -42,20 +34,19 @@ role SQL::Translator::Parser::DDL::MySQL { my $parser_version = 30000; while ($data =~ s#/\*!(\d{5})?(.*?)\*/#($1 && $1 > $parser_version ? '' : $2)#es) { } - + my $result = $parser->startrule($data); -# return $self->error( "Parse failed." ) unless defined $result; die "Parse failed" unless defined $result; - warn "Parse result:".Dumper( $result ) if $DEBUG; - my $schema = Schema->new; + my $translator = $self->translator; + my $schema = $translator->schema; $schema->name($result->{'database_name'}) if $result->{'database_name'}; my @tables = sort { $result->{'tables'}{ $a }{'order'} <=> $result->{'tables'}{ $b }{'order'} } keys %{ $result->{'tables'} }; for my $table_name ( @tables ) { my $tdata = $result->{tables}{ $table_name }; - my $table = Table->new({ name => $tdata->{table_name} }); + my $table = Table->new({ name => $tdata->{table_name}, schema => $schema }); $schema->add_table($table); $table->comments( join "\n", @{$tdata->{comments}} ) if $tdata->{comments}; @@ -274,5 +265,6 @@ role SQL::Translator::Parser::DDL::MySQL { # $column->sql_data_type( $self->data_type_mapping->{$type} || -99999 ); $self->extra->{list} = $list if @$list; # } + return 1; } }