1 package SQL::Translator::Parser::MySQL;
3 # -------------------------------------------------------------------
5 # -------------------------------------------------------------------
6 # Copyright (C) 2002-4 SQLFairy Authors
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
25 SQL::Translator::Parser::MySQL - parser for MySQL
30 use SQL::Translator::Parser::MySQL;
32 my $translator = SQL::Translator->new;
33 $translator->parser("SQL::Translator::Parser::MySQL");
37 The grammar is influenced heavily by Tim Bunce's "mysql2ora" grammar.
39 Here's the word from the MySQL site
40 (http://www.mysql.com/doc/en/CREATE_TABLE.html):
42 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
43 [table_options] [select_statement]
47 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name LIKE old_table_name;
50 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
51 [PRIMARY KEY] [reference_definition]
52 or PRIMARY KEY (index_col_name,...)
53 or KEY [index_name] (index_col_name,...)
54 or INDEX [index_name] (index_col_name,...)
55 or UNIQUE [INDEX] [index_name] (index_col_name,...)
56 or FULLTEXT [INDEX] [index_name] (index_col_name,...)
57 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
58 [reference_definition]
62 TINYINT[(length)] [UNSIGNED] [ZEROFILL]
63 or SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
64 or MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
65 or INT[(length)] [UNSIGNED] [ZEROFILL]
66 or INTEGER[(length)] [UNSIGNED] [ZEROFILL]
67 or BIGINT[(length)] [UNSIGNED] [ZEROFILL]
68 or REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
69 or DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
70 or FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
71 or DECIMAL(length,decimals) [UNSIGNED] [ZEROFILL]
72 or NUMERIC(length,decimals) [UNSIGNED] [ZEROFILL]
73 or CHAR(length) [BINARY]
74 or VARCHAR(length) [BINARY]
87 or ENUM(value1,value2,value3,...)
88 or SET(value1,value2,value3,...)
94 REFERENCES tbl_name [(index_col_name,...)]
95 [MATCH FULL | MATCH PARTIAL]
96 [ON DELETE reference_option]
97 [ON UPDATE reference_option]
100 RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT
103 TYPE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM }
104 or ENGINE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM }
105 or AUTO_INCREMENT = #
106 or AVG_ROW_LENGTH = #
107 or [ DEFAULT ] CHARACTER SET charset_name
108 or CHECKSUM = {0 | 1}
109 or COLLATE collation_name
110 or COMMENT = "string"
113 or PACK_KEYS = {0 | 1 | DEFAULT}
114 or PASSWORD = "string"
115 or DELAY_KEY_WRITE = {0 | 1}
116 or ROW_FORMAT= { default | dynamic | fixed | compressed }
117 or RAID_TYPE= {1 | STRIPED | RAID0 } RAID_CHUNKS=# RAID_CHUNKSIZE=#
118 or UNION = (table_name,[table_name...])
119 or INSERT_METHOD= {NO | FIRST | LAST }
120 or DATA DIRECTORY="absolute path to directory"
121 or INDEX DIRECTORY="absolute path to directory"
124 A subset of the ALTER TABLE syntax that allows addition of foreign keys:
126 ALTER [IGNORE] TABLE tbl_name alter_specification [, alter_specification] ...
129 ADD [CONSTRAINT [symbol]]
130 FOREIGN KEY [index_name] (index_col_name,...)
131 [reference_definition]
133 A subset of INSERT that we ignore:
139 This parser takes a single optional parser_arg C<mysql_parser_version>, which
140 provides the desired version for the target database. Any statement in the processed
141 dump file, that is commented with a version higher than the one supplied, will be stripped.
143 Valid version specifiers for C<mysql_parser_version> are listed L<here|SQL::Translator::Utils/parse_mysql_version>
145 More information about the MySQL comment-syntax: L<http://dev.mysql.com/doc/refman/5.0/en/comments.html>
151 use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
152 $VERSION = sprintf "%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/;
153 $DEBUG = 0 unless defined $DEBUG;
156 use Parse::RecDescent;
158 use Storable qw(dclone);
159 use DBI qw(:sql_types);
160 use base qw(Exporter);
162 use SQL::Translator::Utils qw/parse_mysql_version/;
164 our %type_mapping = (
167 @EXPORT_OK = qw(parse);
169 # Enable warnings within the Parse::RecDescent module.
170 $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
171 $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.
172 $::RD_HINT = 1; # Give out hints to help fix problems.
174 use constant DEFAULT_PARSER_VERSION => 30000;
176 $GRAMMAR = << 'END_OF_GRAMMAR';
179 my ( $database_name, %tables, $table_order, @table_comments, %views, $view_order, %procedures, $proc_order );
184 # The "eofile" rule makes the parser fail if any "statement" rule
185 # fails. Otherwise, the first successful match by a "statement"
186 # won't cause the failure needed to know that the parse, as a whole,
189 startrule : statement(s) eofile {
190 { tables => \%tables, database_name => $database_name, views => \%views, procedures =>\%procedures }
206 use : /use/i WORD "$delimiter"
208 $database_name = $item[2];
209 @table_comments = ();
212 set : /set/i /[^;]+/ "$delimiter"
213 { @table_comments = () }
215 drop : /drop/i TABLE /[^;]+/ "$delimiter"
217 drop : /drop/i WORD(s) "$delimiter"
218 { @table_comments = () }
221 # MySQL strings, unlike common SQL strings, can be double-quoted or
222 # single-quoted, and you can escape the delmiters by doubling (but only the
223 # delimiter) or by backslashing.
225 /'(\\.|''|[^\\\'])*'/ |
226 /"(\\.|""|[^\\\"])*"/
227 # For reference, std sql str: /(?:(?:\')(?:[^\']*(?:(?:\'\')[^\']*)*)(?:\'))//
229 nonstring : /[^;\'"]+/
231 statement_body : (string | nonstring)(s?)
233 insert : /insert/i statement_body "$delimiter"
235 delimiter : /delimiter/i /[\S]+/
236 { $delimiter = $item[2] }
238 empty_statement : "$delimiter"
240 alter : ALTER TABLE table_name alter_specification(s /,/) "$delimiter"
242 my $table_name = $item{'table_name'};
243 die "Cannot ALTER table '$table_name'; it does not exist"
244 unless $tables{ $table_name };
245 for my $definition ( @{ $item[4] } ) {
246 $definition->{'extra'}->{'alter'} = 1;
247 push @{ $tables{ $table_name }{'constraints'} }, $definition;
251 alter_specification : ADD foreign_key_def
252 { $return = $item[2] }
254 create : CREATE /database/i WORD "$delimiter"
255 { @table_comments = () }
257 create : CREATE TEMPORARY(?) TABLE opt_if_not_exists(?) table_name '(' create_definition(s /,/) /(,\s*)?\)/ table_option(s?) "$delimiter"
259 my $table_name = $item{'table_name'};
260 $tables{ $table_name }{'order'} = ++$table_order;
261 $tables{ $table_name }{'table_name'} = $table_name;
263 if ( @table_comments ) {
264 $tables{ $table_name }{'comments'} = [ @table_comments ];
265 @table_comments = ();
269 for my $definition ( @{ $item[7] } ) {
270 if ( $definition->{'supertype'} eq 'field' ) {
271 my $field_name = $definition->{'name'};
272 $tables{ $table_name }{'fields'}{ $field_name } =
273 { %$definition, order => $i };
276 if ( $definition->{'is_primary_key'} ) {
277 push @{ $tables{ $table_name }{'constraints'} },
279 type => 'primary_key',
280 fields => [ $field_name ],
285 elsif ( $definition->{'supertype'} eq 'constraint' ) {
286 push @{ $tables{ $table_name }{'constraints'} }, $definition;
288 elsif ( $definition->{'supertype'} eq 'index' ) {
289 push @{ $tables{ $table_name }{'indices'} }, $definition;
293 if ( my @options = @{ $item{'table_option(s?)'} } ) {
294 for my $option ( @options ) {
295 my ( $key, $value ) = each %$option;
296 if ( $key eq 'comment' ) {
297 push @{ $tables{ $table_name }{'comments'} }, $value;
300 push @{ $tables{ $table_name }{'table_options'} }, $option;
308 opt_if_not_exists : /if not exists/i
310 create : CREATE UNIQUE(?) /(index|key)/i index_name /on/i table_name '(' field_name(s /,/) ')' "$delimiter"
312 @table_comments = ();
313 push @{ $tables{ $item{'table_name'} }{'indices'} },
316 type => $item[2][0] ? 'unique' : 'normal',
322 create : CREATE /trigger/i NAME not_delimiter "$delimiter"
324 @table_comments = ();
327 create : CREATE PROCEDURE NAME not_delimiter "$delimiter"
329 @table_comments = ();
330 my $func_name = $item[3];
332 my $sql = "$item[1] $item[2] $item[3] $item[4]";
334 $procedures{ $func_name }{'order'} = ++$proc_order;
335 $procedures{ $func_name }{'name'} = $func_name;
336 $procedures{ $func_name }{'owner'} = $owner;
337 $procedures{ $func_name }{'sql'} = $sql;
340 PROCEDURE : /procedure/i
343 create : CREATE algorithm /view/i NAME not_delimiter "$delimiter"
345 @table_comments = ();
346 my $view_name = $item[4];
347 my $sql = "$item[1] $item[2] $item[3] $item[4] $item[5]";
349 # Hack to strip database from function calls in SQL
350 $sql =~ s#`\w+`\.(`\w+`\()##g;
352 $views{ $view_name }{'order'} = ++$view_order;
353 $views{ $view_name }{'name'} = $view_name;
354 $views{ $view_name }{'sql'} = $sql;
357 algorithm : /algorithm/i /=/ WORD
359 $return = "$item[1]=$item[3]";
362 not_delimiter : /.*?(?=$delimiter)/is
364 create_definition : constraint
370 comment : /^\s*(?:#|-{2}).*\n/
372 my $comment = $item[1];
373 $comment =~ s/^\s*(#|--)\s*//;
374 $comment =~ s/\s*$//;
378 comment : /\/\*/ /.*?\*\//s
380 my $comment = $item[2];
381 $comment = substr($comment, 0, -2);
382 $comment =~ s/^\s*|\s*$//g;
386 field_comment : /^\s*(?:#|-{2}).*\n/
388 my $comment = $item[1];
389 $comment =~ s/^\s*(#|--)\s*//;
390 $comment =~ s/\s*$//;
395 field_comment2 : /comment/i /'.*?'/
397 my $comment = $item[2];
405 field : field_comment(s?) field_name data_type field_qualifier(s?) field_comment2(?) reference_definition(?) on_update(?) field_comment(s?)
407 my %qualifiers = map { %$_ } @{ $item{'field_qualifier(s?)'} || [] };
408 if ( my @type_quals = @{ $item{'data_type'}{'qualifiers'} || [] } ) {
409 $qualifiers{ $_ } = 1 for @type_quals;
412 my $null = defined $qualifiers{'not_null'}
413 ? $qualifiers{'not_null'} : 1;
414 delete $qualifiers{'not_null'};
416 my @comments = ( @{ $item[1] }, @{ $item[5] }, @{ $item[8] } );
419 supertype => 'field',
420 name => $item{'field_name'},
421 data_type => $item{'data_type'}{'type'},
422 size => $item{'data_type'}{'size'},
423 list => $item{'data_type'}{'list'},
425 constraints => $item{'reference_definition(?)'},
426 comments => [ @comments ],
432 field_qualifier : not_null
435 null => $item{'not_null'},
439 field_qualifier : default_val
442 default => $item{'default_val'},
446 field_qualifier : auto_inc
449 is_auto_inc => $item{'auto_inc'},
453 field_qualifier : primary_key
456 is_primary_key => $item{'primary_key'},
460 field_qualifier : unsigned
463 is_unsigned => $item{'unsigned'},
467 field_qualifier : /character set/i WORD
470 'CHARACTER SET' => $item[2],
474 field_qualifier : /collate/i WORD
481 field_qualifier : /on update/i CURRENT_TIMESTAMP
484 'ON UPDATE' => $item[2],
488 field_qualifier : /unique/i KEY(?)
495 field_qualifier : KEY
502 reference_definition : /references/i table_name parens_field_list(?) match_type(?) on_delete(?) on_update(?)
505 type => 'foreign_key',
506 reference_table => $item[2],
507 reference_fields => $item[3][0],
508 match_type => $item[4][0],
509 on_delete => $item[5][0],
510 on_update => $item[6][0],
514 match_type : /match full/i { 'full' }
516 /match partial/i { 'partial' }
518 on_delete : /on delete/i reference_option
522 /on update/i 'CURRENT_TIMESTAMP'
525 /on update/i reference_option
528 reference_option: /restrict/i |
546 data_type : WORD parens_value_list(s?) type_qualifier(s?)
549 my $size; # field size, applicable only to non-set fields
550 my $list; # set list, applicable only to sets (duh)
552 if ( uc($type) =~ /^(SET|ENUM)$/ ) {
566 qualifiers => $item[3],
570 parens_field_list : '(' field_name(s /,/) ')'
573 parens_value_list : '(' VALUE(s /,/) ')'
576 type_qualifier : /(BINARY|UNSIGNED|ZEROFILL)/i
581 create_index : /create/i /index/i
583 not_null : /not/i /null/i
589 unsigned : /unsigned/i { $return = 0 }
591 #default_val : /default/i /(?:')?[\s\w\d:.-]*(?:')?/
593 # $item[2] =~ s/'//g;
594 # $return = $item[2];
598 /default/i 'CURRENT_TIMESTAMP'
603 /default/i /'(?:.*?\\')*.*?'|(?:')?[\w\d:.-]*(?:')?/
605 $item[2] =~ s/^\s*'|'\s*$//g;
609 auto_inc : /auto_increment/i { 1 }
611 primary_key : /primary/i /key/i { 1 }
613 constraint : primary_key_def
618 foreign_key_def : foreign_key_def_begin parens_field_list reference_definition
621 supertype => 'constraint',
622 type => 'foreign_key',
625 %{ $item{'reference_definition'} },
629 foreign_key_def_begin : /constraint/i /foreign key/i WORD
630 { $return = $item[3] }
632 /constraint/i NAME /foreign key/i
633 { $return = $item[2] }
635 /constraint/i /foreign key/i
639 { $return = $item[2] }
644 primary_key_def : primary_key index_name(?) '(' name_with_opt_paren(s /,/) ')'
647 supertype => 'constraint',
648 name => $item{'index_name(?)'}[0],
649 type => 'primary_key',
654 unique_key_def : UNIQUE KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
657 supertype => 'constraint',
658 name => $item{'index_name(?)'}[0],
664 normal_index : KEY index_name(?) '(' name_with_opt_paren(s /,/) ')'
667 supertype => 'index',
669 name => $item{'index_name(?)'}[0],
674 fulltext_index : /fulltext/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
677 supertype => 'index',
679 name => $item{'index_name(?)'}[0],
684 spatial_index : /spatial/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
687 supertype => 'index',
689 name => $item{'index_name(?)'}[0],
694 name_with_opt_paren : NAME parens_value_list(s?)
695 { $item[2][0] ? "$item[1]($item[2][0][0])" : $item[1] }
699 KEY : /key/i | /index/i
701 table_option : /comment/i /=/ /'.*?'/
703 my $comment = $item[3];
706 $return = { comment => $comment };
708 | /(default )?(charset|character set)/i /\s*=?\s*/ WORD
710 $return = { 'CHARACTER SET' => $item[3] };
714 $return = { 'COLLATE' => $item[2] }
716 | /union/i /\s*=\s*/ '(' table_name(s /,/) ')'
718 $return = { $item[1] => $item[4] };
720 | WORD /\s*=\s*/ WORD
722 $return = { $item[1] => $item[3] };
733 TEMPORARY : /temporary/i
745 NAME : BACKTICK /[^`]+/ BACKTICK
750 VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/
754 # remove leading/trailing quotes
756 $val =~ s/^['"]|['"]$//g;
762 CURRENT_TIMESTAMP : /current_timestamp(\(\))?/i
764 { 'CURRENT_TIMESTAMP' }
768 # -------------------------------------------------------------------
770 my ( $translator, $data ) = @_;
771 my $parser = Parse::RecDescent->new($GRAMMAR);
772 local $::RD_TRACE = $translator->trace ? 1 : undef;
773 local $DEBUG = $translator->debug;
775 unless (defined $parser) {
776 return $translator->error("Error instantiating Parse::RecDescent ".
777 "instance: Bad grammer");
780 # Preprocess for MySQL-specific and not-before-version comments from mysqldump
782 parse_mysql_version ($translator->parser_args->{mysql_parser_version}, 'mysql')
783 || DEFAULT_PARSER_VERSION;
784 while ( $data =~ s#/\*!(\d{5})?(.*?)\*/#($1 && $1 > $parser_version ? '' : $2)#es ) {}
786 my $result = $parser->startrule($data);
787 return $translator->error( "Parse failed." ) unless defined $result;
788 warn "Parse result:".Dumper( $result ) if $DEBUG;
790 my $schema = $translator->schema;
791 $schema->name($result->{'database_name'}) if $result->{'database_name'};
794 $result->{'tables'}{ $a }{'order'}
796 $result->{'tables'}{ $b }{'order'}
797 } keys %{ $result->{'tables'} };
799 for my $table_name ( @tables ) {
800 my $tdata = $result->{tables}{ $table_name };
801 my $table = $schema->add_table(
802 name => $tdata->{'table_name'},
803 ) or die $schema->error;
805 $table->comments( $tdata->{'comments'} );
808 $tdata->{'fields'}->{$a}->{'order'}
810 $tdata->{'fields'}->{$b}->{'order'}
811 } keys %{ $tdata->{'fields'} };
813 for my $fname ( @fields ) {
814 my $fdata = $tdata->{'fields'}{ $fname };
815 my $field = $table->add_field(
816 name => $fdata->{'name'},
817 data_type => $fdata->{'data_type'},
818 size => $fdata->{'size'},
819 default_value => $fdata->{'default'},
820 is_auto_increment => $fdata->{'is_auto_inc'},
821 is_nullable => $fdata->{'null'},
822 comments => $fdata->{'comments'},
823 ) or die $table->error;
825 $table->primary_key( $field->name ) if $fdata->{'is_primary_key'};
827 for my $qual ( qw[ binary unsigned zerofill list collate ],
828 'character set', 'on update' ) {
829 if ( my $val = $fdata->{ $qual } || $fdata->{ uc $qual } ) {
830 next if ref $val eq 'ARRAY' && !@$val;
831 $field->extra( $qual, $val );
835 if ( $fdata->{'has_index'} ) {
839 fields => $fdata->{'name'},
840 ) or die $table->error;
843 if ( $fdata->{'is_unique'} ) {
844 $table->add_constraint(
847 fields => $fdata->{'name'},
848 ) or die $table->error;
851 for my $cdata ( @{ $fdata->{'constraints'} } ) {
852 next unless $cdata->{'type'} eq 'foreign_key';
853 $cdata->{'fields'} ||= [ $field->name ];
854 push @{ $tdata->{'constraints'} }, $cdata;
859 for my $idata ( @{ $tdata->{'indices'} || [] } ) {
860 my $index = $table->add_index(
861 name => $idata->{'name'},
862 type => uc $idata->{'type'},
863 fields => $idata->{'fields'},
864 ) or die $table->error;
867 if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
869 my @ignore_opts = $translator->parser_args->{ignore_opts}?split(/,/,$translator->parser_args->{ignore_opts}):();
871 my $ignores = { map { $_ => 1 } @ignore_opts };
872 foreach my $option (@options) {
873 # make sure the option isn't in ignore list
874 my ($option_key) = keys %$option;
875 push(@cleaned_options, $option) unless (exists $ignores->{$option_key});
878 @cleaned_options = @options;
880 $table->options( \@cleaned_options ) or die $table->error;
883 for my $cdata ( @{ $tdata->{'constraints'} || [] } ) {
884 my $constraint = $table->add_constraint(
885 name => $cdata->{'name'},
886 type => $cdata->{'type'},
887 fields => $cdata->{'fields'},
888 reference_table => $cdata->{'reference_table'},
889 reference_fields => $cdata->{'reference_fields'},
890 match_type => $cdata->{'match_type'} || '',
891 on_delete => $cdata->{'on_delete'} || $cdata->{'on_delete_do'},
892 on_update => $cdata->{'on_update'} || $cdata->{'on_update_do'},
893 ) or die $table->error;
896 # After the constrains and PK/idxs have been created, we normalize fields
897 normalize_field($_) for $table->get_fields;
900 my @procedures = sort {
901 $result->{procedures}->{ $a }->{'order'} <=> $result->{procedures}->{ $b }->{'order'}
902 } keys %{ $result->{procedures} };
903 foreach my $proc_name (@procedures) {
904 $schema->add_procedure(
906 owner => $result->{procedures}->{$proc_name}->{owner},
907 sql => $result->{procedures}->{$proc_name}->{sql},
912 $result->{views}->{ $a }->{'order'} <=> $result->{views}->{ $b }->{'order'}
913 } keys %{ $result->{views} };
914 foreach my $view_name (keys %{ $result->{views} }) {
917 sql => $result->{views}->{$view_name}->{sql},
924 # Takes a field, and returns
925 sub normalize_field {
927 my ($size, $type, $list, $changed) = @_;
929 $size = $field->size;
930 $type = $field->data_type;
931 $list = $field->extra->{list} || [];
933 if ( !ref $size && $size eq 0 ) {
934 if ( lc $type eq 'tinyint' ) {
935 $changed = $size != 4;
938 elsif ( lc $type eq 'smallint' ) {
939 $changed = $size != 6;
942 elsif ( lc $type eq 'mediumint' ) {
943 $changed = $size != 9;
946 elsif ( $type =~ /^int(eger)?$/i ) {
947 $changed = $size != 11 || $type ne 'int';
951 elsif ( lc $type eq 'bigint' ) {
952 $changed = $size != 20;
955 elsif ( lc $type =~ /(float|double|decimal|numeric|real|fixed|dec)/ ) {
956 my $old_size = (ref $size || '') eq 'ARRAY' ? $size : [];
957 $changed = @$old_size != 2 || $old_size->[0] != 8 || $old_size->[1] != 2;
962 if ( $type =~ /^tiny(text|blob)$/i ) {
963 $changed = $size != 255;
966 elsif ( $type =~ /^(blob|text)$/i ) {
967 $changed = $size != 65_535;
970 elsif ( $type =~ /^medium(blob|text)$/i ) {
971 $changed = $size != 16_777_215;
974 elsif ( $type =~ /^long(blob|text)$/i ) {
975 $changed = $size != 4_294_967_295;
976 $size = 4_294_967_295;
978 if ( $field->data_type =~ /(set|enum)/i && !$field->size ) {
979 my %extra = $field->extra;
981 for my $len ( map { length } @{ $extra{'list'} || [] } ) {
982 $longest = $len if $len > $longest;
985 $size = $longest if $longest;
990 # We only want to clone the field, not *everything*
991 { local $field->{table} = undef;
992 $field->parsed_field(dclone($field));
993 $field->parsed_field->{table} = $field->table;
996 $field->data_type($type);
997 $field->sql_data_type( $type_mapping{lc $type} ) if exists $type_mapping{lc $type};
998 $field->extra->{list} = $list if @$list;
1005 # -------------------------------------------------------------------
1006 # Where man is not nature is barren.
1008 # -------------------------------------------------------------------
1014 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>,
1015 Chris Mungall E<lt>cjm@fruitfly.orgE<gt>.
1019 Parse::RecDescent, SQL::Translator::Schema.