From: Ken Youens-Clark Date: Tue, 3 Jun 2003 22:38:18 +0000 (+0000) Subject: Added default field sizes for numeric fields if not specified, removed X-Git-Tag: v0.02~103 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6333c4820af479ee0e4d6e098cc608d2c5514389;p=dbsrgits%2FSQL-Translator.git Added default field sizes for numeric fields if not specified, removed unused rules. --- diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 7f684b0..a2363ad 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.19 2003-06-03 22:11:55 kycl4rk Exp $ +# $Id: MySQL.pm,v 1.20 2003-06-03 22:38:18 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.19 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -343,6 +343,33 @@ data_type : WORD parens_value_list(s?) type_qualifier(s?) $list = []; } + unless ( @{ $size || [] } ) { + if ( lc $type eq 'tinyint' ) { + $size = [4]; + } + elsif ( lc $type eq 'smallint' ) { + $size = [6]; + } + elsif ( lc $type eq 'mediumint' ) { + $size = [9]; + } + elsif ( lc $type eq 'int' ) { + $size = [11]; + } + elsif ( lc $type eq 'bigint' ) { + $size = [20]; + } + elsif ( lc $type eq 'float' ) { + $size = [8,2]; + } + elsif ( lc $type eq 'double' ) { + $size = [8,2]; + } + elsif ( lc $type eq 'decimal' ) { + $size = [8,2]; + } + } + $return = { type => $type, size => $size, @@ -362,13 +389,6 @@ type_qualifier : /(BINARY|UNSIGNED|ZEROFILL)/i field_type : WORD -field_size : '(' num_range ')' { $item{'num_range'} } - -num_range : DIGITS ',' DIGITS - { $return = $item[1].','.$item[3] } - | DIGITS - { $return = $item[1] } - create_index : /create/i /index/i not_null : /not/i /null/i { $return = 0 } @@ -470,12 +490,6 @@ VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/ { $item[1] } | /NULL/ { 'NULL' } -# { -# { -# value => $item[1], -# attribute => $item[2] -# } -# } !;