1 package SQL::Translator::Parser::MySQL;
3 # -------------------------------------------------------------------
4 # Copyright (C) 2002-2009 SQLFairy Authors
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # -------------------------------------------------------------------
23 SQL::Translator::Parser::MySQL - parser for MySQL
28 use SQL::Translator::Parser::MySQL;
30 my $translator = SQL::Translator->new;
31 $translator->parser("SQL::Translator::Parser::MySQL");
35 The grammar is influenced heavily by Tim Bunce's "mysql2ora" grammar.
37 Here's the word from the MySQL site
38 (http://www.mysql.com/doc/en/CREATE_TABLE.html):
40 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
41 [table_options] [select_statement]
45 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name LIKE old_table_name;
48 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
49 [PRIMARY KEY] [reference_definition]
50 or PRIMARY KEY (index_col_name,...)
51 or KEY [index_name] (index_col_name,...)
52 or INDEX [index_name] (index_col_name,...)
53 or UNIQUE [INDEX] [index_name] (index_col_name,...)
54 or FULLTEXT [INDEX] [index_name] (index_col_name,...)
55 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
56 [reference_definition]
60 TINYINT[(length)] [UNSIGNED] [ZEROFILL]
61 or SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
62 or MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
63 or INT[(length)] [UNSIGNED] [ZEROFILL]
64 or INTEGER[(length)] [UNSIGNED] [ZEROFILL]
65 or BIGINT[(length)] [UNSIGNED] [ZEROFILL]
66 or REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
67 or DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
68 or FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
69 or DECIMAL(length,decimals) [UNSIGNED] [ZEROFILL]
70 or NUMERIC(length,decimals) [UNSIGNED] [ZEROFILL]
71 or CHAR(length) [BINARY]
72 or VARCHAR(length) [BINARY]
85 or ENUM(value1,value2,value3,...)
86 or SET(value1,value2,value3,...)
92 REFERENCES tbl_name [(index_col_name,...)]
93 [MATCH FULL | MATCH PARTIAL]
94 [ON DELETE reference_option]
95 [ON UPDATE reference_option]
98 RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT
101 TYPE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM }
102 or ENGINE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM }
103 or AUTO_INCREMENT = #
104 or AVG_ROW_LENGTH = #
105 or [ DEFAULT ] CHARACTER SET charset_name
106 or CHECKSUM = {0 | 1}
107 or COLLATE collation_name
108 or COMMENT = "string"
111 or PACK_KEYS = {0 | 1 | DEFAULT}
112 or PASSWORD = "string"
113 or DELAY_KEY_WRITE = {0 | 1}
114 or ROW_FORMAT= { default | dynamic | fixed | compressed }
115 or RAID_TYPE= {1 | STRIPED | RAID0 } RAID_CHUNKS=# RAID_CHUNKSIZE=#
116 or UNION = (table_name,[table_name...])
117 or INSERT_METHOD= {NO | FIRST | LAST }
118 or DATA DIRECTORY="absolute path to directory"
119 or INDEX DIRECTORY="absolute path to directory"
122 A subset of the ALTER TABLE syntax that allows addition of foreign keys:
124 ALTER [IGNORE] TABLE tbl_name alter_specification [, alter_specification] ...
127 ADD [CONSTRAINT [symbol]]
128 FOREIGN KEY [index_name] (index_col_name,...)
129 [reference_definition]
131 A subset of INSERT that we ignore:
137 This parser takes a single optional parser_arg C<mysql_parser_version>, which
138 provides the desired version for the target database. Any statement in the processed
139 dump file, that is commented with a version higher than the one supplied, will be stripped.
141 Valid version specifiers for C<mysql_parser_version> are listed L<here|SQL::Translator::Utils/parse_mysql_version>
143 More information about the MySQL comment-syntax: L<http://dev.mysql.com/doc/refman/5.0/en/comments.html>
149 use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
151 $DEBUG = 0 unless defined $DEBUG;
154 use Parse::RecDescent;
156 use Storable qw(dclone);
157 use DBI qw(:sql_types);
158 use base qw(Exporter);
160 use SQL::Translator::Utils qw/parse_mysql_version/;
162 our %type_mapping = (
165 @EXPORT_OK = qw(parse);
167 # Enable warnings within the Parse::RecDescent module.
168 $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
169 $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.
170 $::RD_HINT = 1; # Give out hints to help fix problems.
172 use constant DEFAULT_PARSER_VERSION => 30000;
174 $GRAMMAR = << 'END_OF_GRAMMAR';
177 my ( $database_name, %tables, $table_order, @table_comments, %views, $view_order, %procedures, $proc_order );
182 # The "eofile" rule makes the parser fail if any "statement" rule
183 # fails. Otherwise, the first successful match by a "statement"
184 # won't cause the failure needed to know that the parse, as a whole,
187 startrule : statement(s) eofile {
188 { tables => \%tables, database_name => $database_name, views => \%views, procedures =>\%procedures }
204 use : /use/i WORD "$delimiter"
206 $database_name = $item[2];
207 @table_comments = ();
210 set : /set/i /[^;]+/ "$delimiter"
211 { @table_comments = () }
213 drop : /drop/i TABLE /[^;]+/ "$delimiter"
215 drop : /drop/i WORD(s) "$delimiter"
216 { @table_comments = () }
219 # MySQL strings, unlike common SQL strings, can be double-quoted or
220 # single-quoted, and you can escape the delmiters by doubling (but only the
221 # delimiter) or by backslashing.
223 /'(\\.|''|[^\\\'])*'/ |
224 /"(\\.|""|[^\\\"])*"/
225 # For reference, std sql str: /(?:(?:\')(?:[^\']*(?:(?:\'\')[^\']*)*)(?:\'))//
227 nonstring : /[^;\'"]+/
229 statement_body : (string | nonstring)(s?)
231 insert : /insert/i statement_body "$delimiter"
233 delimiter : /delimiter/i /[\S]+/
234 { $delimiter = $item[2] }
236 empty_statement : "$delimiter"
238 alter : ALTER TABLE table_name alter_specification(s /,/) "$delimiter"
240 my $table_name = $item{'table_name'};
241 die "Cannot ALTER table '$table_name'; it does not exist"
242 unless $tables{ $table_name };
243 for my $definition ( @{ $item[4] } ) {
244 $definition->{'extra'}->{'alter'} = 1;
245 push @{ $tables{ $table_name }{'constraints'} }, $definition;
249 alter_specification : ADD foreign_key_def
250 { $return = $item[2] }
252 create : CREATE /database/i WORD "$delimiter"
253 { @table_comments = () }
255 create : CREATE TEMPORARY(?) TABLE opt_if_not_exists(?) table_name '(' create_definition(s /,/) /(,\s*)?\)/ table_option(s?) "$delimiter"
257 my $table_name = $item{'table_name'};
258 $tables{ $table_name }{'order'} = ++$table_order;
259 $tables{ $table_name }{'table_name'} = $table_name;
261 if ( @table_comments ) {
262 $tables{ $table_name }{'comments'} = [ @table_comments ];
263 @table_comments = ();
267 for my $definition ( @{ $item[7] } ) {
268 if ( $definition->{'supertype'} eq 'field' ) {
269 my $field_name = $definition->{'name'};
270 $tables{ $table_name }{'fields'}{ $field_name } =
271 { %$definition, order => $i };
274 if ( $definition->{'is_primary_key'} ) {
275 push @{ $tables{ $table_name }{'constraints'} },
277 type => 'primary_key',
278 fields => [ $field_name ],
283 elsif ( $definition->{'supertype'} eq 'constraint' ) {
284 push @{ $tables{ $table_name }{'constraints'} }, $definition;
286 elsif ( $definition->{'supertype'} eq 'index' ) {
287 push @{ $tables{ $table_name }{'indices'} }, $definition;
291 if ( my @options = @{ $item{'table_option(s?)'} } ) {
292 for my $option ( @options ) {
293 my ( $key, $value ) = each %$option;
294 if ( $key eq 'comment' ) {
295 push @{ $tables{ $table_name }{'comments'} }, $value;
298 push @{ $tables{ $table_name }{'table_options'} }, $option;
306 opt_if_not_exists : /if not exists/i
308 create : CREATE UNIQUE(?) /(index|key)/i index_name /on/i table_name '(' field_name(s /,/) ')' "$delimiter"
310 @table_comments = ();
311 push @{ $tables{ $item{'table_name'} }{'indices'} },
314 type => $item[2][0] ? 'unique' : 'normal',
320 create : CREATE /trigger/i NAME not_delimiter "$delimiter"
322 @table_comments = ();
325 create : CREATE PROCEDURE NAME not_delimiter "$delimiter"
327 @table_comments = ();
328 my $func_name = $item[3];
330 my $sql = "$item[1] $item[2] $item[3] $item[4]";
332 $procedures{ $func_name }{'order'} = ++$proc_order;
333 $procedures{ $func_name }{'name'} = $func_name;
334 $procedures{ $func_name }{'owner'} = $owner;
335 $procedures{ $func_name }{'sql'} = $sql;
338 PROCEDURE : /procedure/i
341 create : CREATE algorithm /view/i NAME not_delimiter "$delimiter"
343 @table_comments = ();
344 my $view_name = $item[4];
345 my $sql = "$item[1] $item[2] $item[3] $item[4] $item[5]";
347 # Hack to strip database from function calls in SQL
348 $sql =~ s#`\w+`\.(`\w+`\()##g;
350 $views{ $view_name }{'order'} = ++$view_order;
351 $views{ $view_name }{'name'} = $view_name;
352 $views{ $view_name }{'sql'} = $sql;
355 algorithm : /algorithm/i /=/ WORD
357 $return = "$item[1]=$item[3]";
360 not_delimiter : /.*?(?=$delimiter)/is
362 create_definition : constraint
368 comment : /^\s*(?:#|-{2}).*\n/
370 my $comment = $item[1];
371 $comment =~ s/^\s*(#|--)\s*//;
372 $comment =~ s/\s*$//;
376 comment : /\/\*/ /.*?\*\//s
378 my $comment = $item[2];
379 $comment = substr($comment, 0, -2);
380 $comment =~ s/^\s*|\s*$//g;
384 field_comment : /^\s*(?:#|-{2}).*\n/
386 my $comment = $item[1];
387 $comment =~ s/^\s*(#|--)\s*//;
388 $comment =~ s/\s*$//;
393 field_comment2 : /comment/i /'.*?'/
395 my $comment = $item[2];
403 field : field_comment(s?) field_name data_type field_qualifier(s?) field_comment2(?) reference_definition(?) on_update(?) field_comment(s?)
405 my %qualifiers = map { %$_ } @{ $item{'field_qualifier(s?)'} || [] };
406 if ( my @type_quals = @{ $item{'data_type'}{'qualifiers'} || [] } ) {
407 $qualifiers{ $_ } = 1 for @type_quals;
410 my $null = defined $qualifiers{'not_null'}
411 ? $qualifiers{'not_null'} : 1;
412 delete $qualifiers{'not_null'};
414 my @comments = ( @{ $item[1] }, @{ $item[5] }, @{ $item[8] } );
417 supertype => 'field',
418 name => $item{'field_name'},
419 data_type => $item{'data_type'}{'type'},
420 size => $item{'data_type'}{'size'},
421 list => $item{'data_type'}{'list'},
423 constraints => $item{'reference_definition(?)'},
424 comments => [ @comments ],
430 field_qualifier : not_null
433 null => $item{'not_null'},
437 field_qualifier : default_val
440 default => $item{'default_val'},
444 field_qualifier : auto_inc
447 is_auto_inc => $item{'auto_inc'},
451 field_qualifier : primary_key
454 is_primary_key => $item{'primary_key'},
458 field_qualifier : unsigned
461 is_unsigned => $item{'unsigned'},
465 field_qualifier : /character set/i WORD
468 'CHARACTER SET' => $item[2],
472 field_qualifier : /collate/i WORD
479 field_qualifier : /on update/i CURRENT_TIMESTAMP
482 'ON UPDATE' => $item[2],
486 field_qualifier : /unique/i KEY(?)
493 field_qualifier : KEY
500 reference_definition : /references/i table_name parens_field_list(?) match_type(?) on_delete(?) on_update(?)
503 type => 'foreign_key',
504 reference_table => $item[2],
505 reference_fields => $item[3][0],
506 match_type => $item[4][0],
507 on_delete => $item[5][0],
508 on_update => $item[6][0],
512 match_type : /match full/i { 'full' }
514 /match partial/i { 'partial' }
516 on_delete : /on delete/i reference_option
520 /on update/i 'CURRENT_TIMESTAMP'
523 /on update/i reference_option
526 reference_option: /restrict/i |
544 data_type : WORD parens_value_list(s?) type_qualifier(s?)
547 my $size; # field size, applicable only to non-set fields
548 my $list; # set list, applicable only to sets (duh)
550 if ( uc($type) =~ /^(SET|ENUM)$/ ) {
564 qualifiers => $item[3],
568 parens_field_list : '(' field_name(s /,/) ')'
571 parens_value_list : '(' VALUE(s /,/) ')'
574 type_qualifier : /(BINARY|UNSIGNED|ZEROFILL)/i
579 create_index : /create/i /index/i
581 not_null : /not/i /null/i
587 unsigned : /unsigned/i { $return = 0 }
589 #default_val : /default/i /(?:')?[\s\w\d:.-]*(?:')?/
591 # $item[2] =~ s/'//g;
592 # $return = $item[2];
596 /default/i 'CURRENT_TIMESTAMP'
601 /default/i /'(?:.*?\\')*.*?'|(?:')?[\w\d:.-]*(?:')?/
603 $item[2] =~ s/^\s*'|'\s*$//g;
607 auto_inc : /auto_increment/i { 1 }
609 primary_key : /primary/i /key/i { 1 }
611 constraint : primary_key_def
616 foreign_key_def : foreign_key_def_begin parens_field_list reference_definition
619 supertype => 'constraint',
620 type => 'foreign_key',
623 %{ $item{'reference_definition'} },
627 foreign_key_def_begin : /constraint/i /foreign key/i WORD
628 { $return = $item[3] }
630 /constraint/i NAME /foreign key/i
631 { $return = $item[2] }
633 /constraint/i /foreign key/i
637 { $return = $item[2] }
642 primary_key_def : primary_key index_name(?) '(' name_with_opt_paren(s /,/) ')'
645 supertype => 'constraint',
646 name => $item{'index_name(?)'}[0],
647 type => 'primary_key',
652 unique_key_def : UNIQUE KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
655 supertype => 'constraint',
656 name => $item{'index_name(?)'}[0],
662 normal_index : KEY index_name(?) '(' name_with_opt_paren(s /,/) ')'
665 supertype => 'index',
667 name => $item{'index_name(?)'}[0],
672 fulltext_index : /fulltext/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
675 supertype => 'index',
677 name => $item{'index_name(?)'}[0],
682 spatial_index : /spatial/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
685 supertype => 'index',
687 name => $item{'index_name(?)'}[0],
692 name_with_opt_paren : NAME parens_value_list(s?)
693 { $item[2][0] ? "$item[1]($item[2][0][0])" : $item[1] }
697 KEY : /key/i | /index/i
699 table_option : /comment/i /=/ /'.*?'/
701 my $comment = $item[3];
704 $return = { comment => $comment };
706 | /(default )?(charset|character set)/i /\s*=?\s*/ WORD
708 $return = { 'CHARACTER SET' => $item[3] };
712 $return = { 'COLLATE' => $item[2] }
714 | /union/i /\s*=\s*/ '(' table_name(s /,/) ')'
716 $return = { $item[1] => $item[4] };
718 | WORD /\s*=\s*/ MAYBE_QUOTED_WORD
720 $return = { $item[1] => $item[3] };
723 MAYBE_QUOTED_WORD: /\w+/
737 TEMPORARY : /temporary/i
749 NAME : BACKTICK /[^`]+/ BACKTICK
754 VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/
758 # remove leading/trailing quotes
760 $val =~ s/^['"]|['"]$//g;
766 CURRENT_TIMESTAMP : /current_timestamp(\(\))?/i
768 { 'CURRENT_TIMESTAMP' }
772 # -------------------------------------------------------------------
774 my ( $translator, $data ) = @_;
775 my $parser = Parse::RecDescent->new($GRAMMAR);
776 local $::RD_TRACE = $translator->trace ? 1 : undef;
777 local $DEBUG = $translator->debug;
779 unless (defined $parser) {
780 return $translator->error("Error instantiating Parse::RecDescent ".
781 "instance: Bad grammer");
784 # Preprocess for MySQL-specific and not-before-version comments from mysqldump
786 parse_mysql_version ($translator->parser_args->{mysql_parser_version}, 'mysql')
787 || DEFAULT_PARSER_VERSION;
788 while ( $data =~ s#/\*!(\d{5})?(.*?)\*/#($1 && $1 > $parser_version ? '' : $2)#es ) {}
790 my $result = $parser->startrule($data);
791 return $translator->error( "Parse failed." ) unless defined $result;
792 warn "Parse result:".Dumper( $result ) if $DEBUG;
794 my $schema = $translator->schema;
795 $schema->name($result->{'database_name'}) if $result->{'database_name'};
798 $result->{'tables'}{ $a }{'order'}
800 $result->{'tables'}{ $b }{'order'}
801 } keys %{ $result->{'tables'} };
803 for my $table_name ( @tables ) {
804 my $tdata = $result->{tables}{ $table_name };
805 my $table = $schema->add_table(
806 name => $tdata->{'table_name'},
807 ) or die $schema->error;
809 $table->comments( $tdata->{'comments'} );
812 $tdata->{'fields'}->{$a}->{'order'}
814 $tdata->{'fields'}->{$b}->{'order'}
815 } keys %{ $tdata->{'fields'} };
817 for my $fname ( @fields ) {
818 my $fdata = $tdata->{'fields'}{ $fname };
819 my $field = $table->add_field(
820 name => $fdata->{'name'},
821 data_type => $fdata->{'data_type'},
822 size => $fdata->{'size'},
823 default_value => $fdata->{'default'},
824 is_auto_increment => $fdata->{'is_auto_inc'},
825 is_nullable => $fdata->{'null'},
826 comments => $fdata->{'comments'},
827 ) or die $table->error;
829 $table->primary_key( $field->name ) if $fdata->{'is_primary_key'};
831 for my $qual ( qw[ binary unsigned zerofill list collate ],
832 'character set', 'on update' ) {
833 if ( my $val = $fdata->{ $qual } || $fdata->{ uc $qual } ) {
834 next if ref $val eq 'ARRAY' && !@$val;
835 $field->extra( $qual, $val );
839 if ( $fdata->{'has_index'} ) {
843 fields => $fdata->{'name'},
844 ) or die $table->error;
847 if ( $fdata->{'is_unique'} ) {
848 $table->add_constraint(
851 fields => $fdata->{'name'},
852 ) or die $table->error;
855 for my $cdata ( @{ $fdata->{'constraints'} } ) {
856 next unless $cdata->{'type'} eq 'foreign_key';
857 $cdata->{'fields'} ||= [ $field->name ];
858 push @{ $tdata->{'constraints'} }, $cdata;
863 for my $idata ( @{ $tdata->{'indices'} || [] } ) {
864 my $index = $table->add_index(
865 name => $idata->{'name'},
866 type => uc $idata->{'type'},
867 fields => $idata->{'fields'},
868 ) or die $table->error;
871 if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
873 my @ignore_opts = $translator->parser_args->{ignore_opts}?split(/,/,$translator->parser_args->{ignore_opts}):();
875 my $ignores = { map { $_ => 1 } @ignore_opts };
876 foreach my $option (@options) {
877 # make sure the option isn't in ignore list
878 my ($option_key) = keys %$option;
879 push(@cleaned_options, $option) unless (exists $ignores->{$option_key});
882 @cleaned_options = @options;
884 $table->options( \@cleaned_options ) or die $table->error;
887 for my $cdata ( @{ $tdata->{'constraints'} || [] } ) {
888 my $constraint = $table->add_constraint(
889 name => $cdata->{'name'},
890 type => $cdata->{'type'},
891 fields => $cdata->{'fields'},
892 reference_table => $cdata->{'reference_table'},
893 reference_fields => $cdata->{'reference_fields'},
894 match_type => $cdata->{'match_type'} || '',
895 on_delete => $cdata->{'on_delete'} || $cdata->{'on_delete_do'},
896 on_update => $cdata->{'on_update'} || $cdata->{'on_update_do'},
897 ) or die $table->error;
900 # After the constrains and PK/idxs have been created, we normalize fields
901 normalize_field($_) for $table->get_fields;
904 my @procedures = sort {
905 $result->{procedures}->{ $a }->{'order'} <=> $result->{procedures}->{ $b }->{'order'}
906 } keys %{ $result->{procedures} };
907 foreach my $proc_name (@procedures) {
908 $schema->add_procedure(
910 owner => $result->{procedures}->{$proc_name}->{owner},
911 sql => $result->{procedures}->{$proc_name}->{sql},
916 $result->{views}->{ $a }->{'order'} <=> $result->{views}->{ $b }->{'order'}
917 } keys %{ $result->{views} };
918 foreach my $view_name (keys %{ $result->{views} }) {
921 sql => $result->{views}->{$view_name}->{sql},
928 # Takes a field, and returns
929 sub normalize_field {
931 my ($size, $type, $list, $changed) = @_;
933 $size = $field->size;
934 $type = $field->data_type;
935 $list = $field->extra->{list} || [];
937 if ( !ref $size && $size eq 0 ) {
938 if ( lc $type eq 'tinyint' ) {
939 $changed = $size != 4;
942 elsif ( lc $type eq 'smallint' ) {
943 $changed = $size != 6;
946 elsif ( lc $type eq 'mediumint' ) {
947 $changed = $size != 9;
950 elsif ( $type =~ /^int(eger)?$/i ) {
951 $changed = $size != 11 || $type ne 'int';
955 elsif ( lc $type eq 'bigint' ) {
956 $changed = $size != 20;
959 elsif ( lc $type =~ /(float|double|decimal|numeric|real|fixed|dec)/ ) {
960 my $old_size = (ref $size || '') eq 'ARRAY' ? $size : [];
961 $changed = @$old_size != 2 || $old_size->[0] != 8 || $old_size->[1] != 2;
966 if ( $type =~ /^tiny(text|blob)$/i ) {
967 $changed = $size != 255;
970 elsif ( $type =~ /^(blob|text)$/i ) {
971 $changed = $size != 65_535;
974 elsif ( $type =~ /^medium(blob|text)$/i ) {
975 $changed = $size != 16_777_215;
978 elsif ( $type =~ /^long(blob|text)$/i ) {
979 $changed = $size != 4_294_967_295;
980 $size = 4_294_967_295;
982 if ( $field->data_type =~ /(set|enum)/i && !$field->size ) {
983 my %extra = $field->extra;
985 for my $len ( map { length } @{ $extra{'list'} || [] } ) {
986 $longest = $len if $len > $longest;
989 $size = $longest if $longest;
994 # We only want to clone the field, not *everything*
995 { local $field->{table} = undef;
996 $field->parsed_field(dclone($field));
997 $field->parsed_field->{table} = $field->table;
1000 $field->data_type($type);
1001 $field->sql_data_type( $type_mapping{lc $type} ) if exists $type_mapping{lc $type};
1002 $field->extra->{list} = $list if @$list;
1009 # -------------------------------------------------------------------
1010 # Where man is not nature is barren.
1012 # -------------------------------------------------------------------
1018 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>,
1019 Chris Mungall E<lt>cjm@fruitfly.orgE<gt>.
1023 Parse::RecDescent, SQL::Translator::Schema.