Added FIXED as DEC per http://www.mysql.com/doc/en/Column_types.html
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / MySQL.pm
index 64134fc..01c95da 100644 (file)
@@ -1,7 +1,7 @@
 package SQL::Translator::Parser::MySQL;
 
 # -------------------------------------------------------------------
-# $Id: MySQL.pm,v 1.28 2003-08-04 15:19:08 kycl4rk Exp $
+# $Id: MySQL.pm,v 1.32 2003-08-17 07:44:06 rossta 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.28 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.32 $ =~ /(\d+)\.(\d+)/;
 $DEBUG   = 0 unless defined $DEBUG;
 
 use Data::Dumper;
@@ -156,12 +156,15 @@ eofile : /^\Z/
 
 statement : comment
     | use
+    | set
     | drop
     | create
     | <error>
 
 use : /use/i WORD ';'
 
+set : /set/i /[^;]+/ ';'
+
 drop : /drop/i WORD(s) ';'
 
 create : CREATE /database/i WORD ';'
@@ -237,7 +240,7 @@ create_definition : constraint
 
 comment : /^\s*(?:#|-{2}).*\n/ { 
     my $comment =  $item[1];
-    $comment    =~ s/^\s*(#|-{2})//;
+    $comment    =~ s/^\s*(#|-{2})\s*//;
     $comment    =~ s/\s*$//;
     $return     = $comment;
 }
@@ -382,7 +385,7 @@ data_type    : WORD parens_value_list(s?) type_qualifier(s?)
             elsif ( lc $type eq 'bigint' ) {
                 $size = [20];
             }
-            elsif ( lc $type =~ /(float|double|decimal|numeric|real)/ ) {
+            elsif ( lc $type =~ /(float|double|decimal|numeric|real|fixed|dec)/ ) {
                 $size = [8,2];
             }
         }
@@ -440,7 +443,7 @@ foreign_key_def : opt_constraint(?) /foreign key/i WORD(?) parens_field_list ref
 
 opt_constraint : /constraint/i WORD
 
-primary_key_def : primary_key index_name(?) '(' field_name(s /,/) ')'
+primary_key_def : primary_key index_name(?) '(' name_with_opt_paren(s /,/) ')'
     { 
         $return       = { 
             supertype => 'constraint',
@@ -586,7 +589,7 @@ sub parse {
 
             if ( $field->data_type =~ /(set|enum)/i && !$field->size ) {
                 my %extra = $field->extra;
-                my $longest;
+                my $longest = 0;
                 for my $len ( map { length } @{ $extra{'list'} || [] } ) {
                     $longest = $len if $len > $longest;
                 }