X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FMySQL.pm;h=6b5e631b10195433005a79ed0a170dbe295d416e;hb=cce2cd786d194180f44baff4d1deb69a141467ee;hp=fe8132fa4dbecd881eb4775683d6b74f9fc330c7;hpb=58a88238267bb1a8ae6ac8721b03c596ed3d87b9;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index fe8132f..6b5e631 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::MySQL; # ------------------------------------------------------------------- -# $Id: MySQL.pm,v 1.15 2003-04-30 21:58:40 kycl4rk Exp $ +# $Id: MySQL.pm,v 1.18 2003-05-09 19:51:04 kycl4rk Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # darren chamberlain , @@ -123,7 +123,7 @@ Here's the word from the MySQL site use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -143,7 +143,9 @@ my $parser; # should we do this? There's no programmic way to $GRAMMAR = q! -{ our ( %tables, $table_order ) } +{ + our ( %tables, $table_order ); +} # # The "eofile" rule makes the parser fail if any "statement" rule @@ -366,7 +368,7 @@ not_null : /not/i /null/i { $return = 0 } unsigned : /unsigned/i { $return = 0 } -default_val : /default/i /(?:')?[\w\d.-]*(?:')?/ +default_val : /default/i /(?:')?[\w\d:.-]*(?:')?/ { $item[2] =~ s/'//g; $return = $item[2]; @@ -467,26 +469,53 @@ sub parse { my $result = $parser->startrule($data); die "Parse failed.\n" unless defined $result; - warn Dumper($result) if $DEBUG; + warn Dumper( $result ) if $DEBUG; + + my $schema = $translator->schema; + for my $table_name ( keys %{ $result } ) { + my $tdata = $result->{ $table_name }; + my $table = $schema->add_table( + name => $tdata->{'table_name'}, + ); + + my @fields = sort { + $tdata->{'fields'}->{$a}->{'order'} + <=> + $tdata->{'fields'}->{$b}->{'order'} + } keys %{ $tdata->{'fields'} }; + + for my $fname ( @fields ) { + my $fdata = $tdata->{'fields'}{ $fname }; + my $field = $table->add_field( + name => $fdata->{'name'}, + data_type => $fdata->{'data_type'}, + size => $fdata->{'size'}, + default_value => $fdata->{'default'}, + is_auto_increment => $fdata->{'is_auto_inc'}, + is_nullable => $fdata->{'null'}, + ); + } + } + return $result; } 1; -#----------------------------------------------------- +# ---------------------------------------------------- # Where man is not nature is barren. # William Blake -#----------------------------------------------------- +# ---------------------------------------------------- =pod =head1 AUTHOR Ken Y. Clark Ekclark@cpan.orgE, -Chris Mungall +Chris Mungall Ecjm@fruitfly.orgE. =head1 SEE ALSO -perl(1), Parse::RecDescent. +perl(1), Parse::RecDescent, SQL::Translator::Schema. =cut