added width and height options for graphviz out. no docs
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / MySQL.pm
index fe8132f..6b5e631 100644 (file)
@@ -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 <kclark@cpan.org>,
 #                    darren chamberlain <darren@cpan.org>,
@@ -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 E<lt>kclark@cpan.orgE<gt>,
-Chris Mungall
+Chris Mungall E<lt>cjm@fruitfly.orgE<gt>.
 
 =head1 SEE ALSO
 
-perl(1), Parse::RecDescent.
+perl(1), Parse::RecDescent, SQL::Translator::Schema.
 
 =cut