1 package SQL::Translator::Parser::MySQL;
3 # -------------------------------------------------------------------
5 # -------------------------------------------------------------------
6 # Copyright (C) 2002-2009 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 $GRAMMAR @EXPORT_OK ];
152 $DEBUG = 0 unless defined $DEBUG;
155 use Parse::RecDescent;
157 use Storable qw(dclone);
158 use DBI qw(:sql_types);
159 use base qw(Exporter);
161 use SQL::Translator::Utils qw/parse_mysql_version/;
163 our %type_mapping = (
166 @EXPORT_OK = qw(parse);
168 # Enable warnings within the Parse::RecDescent module.
169 $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
170 $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.
171 $::RD_HINT = 1; # Give out hints to help fix problems.
173 use constant DEFAULT_PARSER_VERSION => 30000;
175 $GRAMMAR = << 'END_OF_GRAMMAR';
178 my ( $database_name, %tables, $table_order, @table_comments, %views, $view_order, %procedures, $proc_order );
183 # The "eofile" rule makes the parser fail if any "statement" rule
184 # fails. Otherwise, the first successful match by a "statement"
185 # won't cause the failure needed to know that the parse, as a whole,
188 startrule : statement(s) eofile {
189 { tables => \%tables, database_name => $database_name, views => \%views, procedures =>\%procedures }
205 use : /use/i WORD "$delimiter"
207 $database_name = $item[2];
208 @table_comments = ();
211 set : /set/i /[^;]+/ "$delimiter"
212 { @table_comments = () }
214 drop : /drop/i TABLE /[^;]+/ "$delimiter"
216 drop : /drop/i WORD(s) "$delimiter"
217 { @table_comments = () }
220 # MySQL strings, unlike common SQL strings, can be double-quoted or
221 # single-quoted, and you can escape the delmiters by doubling (but only the
222 # delimiter) or by backslashing.
224 /'(\\.|''|[^\\\'])*'/ |
225 /"(\\.|""|[^\\\"])*"/
226 # For reference, std sql str: /(?:(?:\')(?:[^\']*(?:(?:\'\')[^\']*)*)(?:\'))//
228 nonstring : /[^;\'"]+/
230 statement_body : (string | nonstring)(s?)
232 insert : /insert/i statement_body "$delimiter"
234 delimiter : /delimiter/i /[\S]+/
235 { $delimiter = $item[2] }
237 empty_statement : "$delimiter"
239 alter : ALTER TABLE table_name alter_specification(s /,/) "$delimiter"
241 my $table_name = $item{'table_name'};
242 die "Cannot ALTER table '$table_name'; it does not exist"
243 unless $tables{ $table_name };
244 for my $definition ( @{ $item[4] } ) {
245 $definition->{'extra'}->{'alter'} = 1;
246 push @{ $tables{ $table_name }{'constraints'} }, $definition;
250 alter_specification : ADD foreign_key_def
251 { $return = $item[2] }
253 create : CREATE /database/i WORD "$delimiter"
254 { @table_comments = () }
256 create : CREATE TEMPORARY(?) TABLE opt_if_not_exists(?) table_name '(' create_definition(s /,/) /(,\s*)?\)/ table_option(s?) "$delimiter"
258 my $table_name = $item{'table_name'};
259 $tables{ $table_name }{'order'} = ++$table_order;
260 $tables{ $table_name }{'table_name'} = $table_name;
262 if ( @table_comments ) {
263 $tables{ $table_name }{'comments'} = [ @table_comments ];
264 @table_comments = ();
268 for my $definition ( @{ $item[7] } ) {
269 if ( $definition->{'supertype'} eq 'field' ) {
270 my $field_name = $definition->{'name'};
271 $tables{ $table_name }{'fields'}{ $field_name } =
272 { %$definition, order => $i };
275 if ( $definition->{'is_primary_key'} ) {
276 push @{ $tables{ $table_name }{'constraints'} },
278 type => 'primary_key',
279 fields => [ $field_name ],
284 elsif ( $definition->{'supertype'} eq 'constraint' ) {
285 push @{ $tables{ $table_name }{'constraints'} }, $definition;
287 elsif ( $definition->{'supertype'} eq 'index' ) {
288 push @{ $tables{ $table_name }{'indices'} }, $definition;
292 if ( my @options = @{ $item{'table_option(s?)'} } ) {
293 for my $option ( @options ) {
294 my ( $key, $value ) = each %$option;
295 if ( $key eq 'comment' ) {
296 push @{ $tables{ $table_name }{'comments'} }, $value;
299 push @{ $tables{ $table_name }{'table_options'} }, $option;
307 opt_if_not_exists : /if not exists/i
309 create : CREATE UNIQUE(?) /(index|key)/i index_name /on/i table_name '(' field_name(s /,/) ')' "$delimiter"
311 @table_comments = ();
312 push @{ $tables{ $item{'table_name'} }{'indices'} },
315 type => $item[2][0] ? 'unique' : 'normal',
321 create : CREATE /trigger/i NAME not_delimiter "$delimiter"
323 @table_comments = ();
326 create : CREATE PROCEDURE NAME not_delimiter "$delimiter"
328 @table_comments = ();
329 my $func_name = $item[3];
331 my $sql = "$item[1] $item[2] $item[3] $item[4]";
333 $procedures{ $func_name }{'order'} = ++$proc_order;
334 $procedures{ $func_name }{'name'} = $func_name;
335 $procedures{ $func_name }{'owner'} = $owner;
336 $procedures{ $func_name }{'sql'} = $sql;
339 PROCEDURE : /procedure/i
342 create : CREATE algorithm /view/i NAME not_delimiter "$delimiter"
344 @table_comments = ();
345 my $view_name = $item[4];
346 my $sql = "$item[1] $item[2] $item[3] $item[4] $item[5]";
348 # Hack to strip database from function calls in SQL
349 $sql =~ s#`\w+`\.(`\w+`\()##g;
351 $views{ $view_name }{'order'} = ++$view_order;
352 $views{ $view_name }{'name'} = $view_name;
353 $views{ $view_name }{'sql'} = $sql;
356 algorithm : /algorithm/i /=/ WORD
358 $return = "$item[1]=$item[3]";
361 not_delimiter : /.*?(?=$delimiter)/is
363 create_definition : constraint
369 comment : /^\s*(?:#|-{2}).*\n/
371 my $comment = $item[1];
372 $comment =~ s/^\s*(#|--)\s*//;
373 $comment =~ s/\s*$//;
377 comment : /\/\*/ /.*?\*\//s
379 my $comment = $item[2];
380 $comment = substr($comment, 0, -2);
381 $comment =~ s/^\s*|\s*$//g;
385 field_comment : /^\s*(?:#|-{2}).*\n/
387 my $comment = $item[1];
388 $comment =~ s/^\s*(#|--)\s*//;
389 $comment =~ s/\s*$//;
394 field_comment2 : /comment/i /'.*?'/
396 my $comment = $item[2];
404 field : field_comment(s?) field_name data_type field_qualifier(s?) field_comment2(?) reference_definition(?) on_update(?) field_comment(s?)
406 my %qualifiers = map { %$_ } @{ $item{'field_qualifier(s?)'} || [] };
407 if ( my @type_quals = @{ $item{'data_type'}{'qualifiers'} || [] } ) {
408 $qualifiers{ $_ } = 1 for @type_quals;
411 my $null = defined $qualifiers{'not_null'}
412 ? $qualifiers{'not_null'} : 1;
413 delete $qualifiers{'not_null'};
415 my @comments = ( @{ $item[1] }, @{ $item[5] }, @{ $item[8] } );
418 supertype => 'field',
419 name => $item{'field_name'},
420 data_type => $item{'data_type'}{'type'},
421 size => $item{'data_type'}{'size'},
422 list => $item{'data_type'}{'list'},
424 constraints => $item{'reference_definition(?)'},
425 comments => [ @comments ],
431 field_qualifier : not_null
434 null => $item{'not_null'},
438 field_qualifier : default_val
441 default => $item{'default_val'},
445 field_qualifier : auto_inc
448 is_auto_inc => $item{'auto_inc'},
452 field_qualifier : primary_key
455 is_primary_key => $item{'primary_key'},
459 field_qualifier : unsigned
462 is_unsigned => $item{'unsigned'},
466 field_qualifier : /character set/i WORD
469 'CHARACTER SET' => $item[2],
473 field_qualifier : /collate/i WORD
480 field_qualifier : /on update/i CURRENT_TIMESTAMP
483 'ON UPDATE' => $item[2],
487 field_qualifier : /unique/i KEY(?)
494 field_qualifier : KEY
501 reference_definition : /references/i table_name parens_field_list(?) match_type(?) on_delete(?) on_update(?)
504 type => 'foreign_key',
505 reference_table => $item[2],
506 reference_fields => $item[3][0],
507 match_type => $item[4][0],
508 on_delete => $item[5][0],
509 on_update => $item[6][0],
513 match_type : /match full/i { 'full' }
515 /match partial/i { 'partial' }
517 on_delete : /on delete/i reference_option
521 /on update/i 'CURRENT_TIMESTAMP'
524 /on update/i reference_option
527 reference_option: /restrict/i |
545 data_type : WORD parens_value_list(s?) type_qualifier(s?)
548 my $size; # field size, applicable only to non-set fields
549 my $list; # set list, applicable only to sets (duh)
551 if ( uc($type) =~ /^(SET|ENUM)$/ ) {
565 qualifiers => $item[3],
569 parens_field_list : '(' field_name(s /,/) ')'
572 parens_value_list : '(' VALUE(s /,/) ')'
575 type_qualifier : /(BINARY|UNSIGNED|ZEROFILL)/i
580 create_index : /create/i /index/i
582 not_null : /not/i /null/i
588 unsigned : /unsigned/i { $return = 0 }
590 #default_val : /default/i /(?:')?[\s\w\d:.-]*(?:')?/
592 # $item[2] =~ s/'//g;
593 # $return = $item[2];
597 /default/i 'CURRENT_TIMESTAMP'
602 /default/i /'(?:.*?\\')*.*?'|(?:')?[\w\d:.-]*(?:')?/
604 $item[2] =~ s/^\s*'|'\s*$//g;
608 auto_inc : /auto_increment/i { 1 }
610 primary_key : /primary/i /key/i { 1 }
612 constraint : primary_key_def
617 foreign_key_def : foreign_key_def_begin parens_field_list reference_definition
620 supertype => 'constraint',
621 type => 'foreign_key',
624 %{ $item{'reference_definition'} },
628 foreign_key_def_begin : /constraint/i /foreign key/i WORD
629 { $return = $item[3] }
631 /constraint/i NAME /foreign key/i
632 { $return = $item[2] }
634 /constraint/i /foreign key/i
638 { $return = $item[2] }
643 primary_key_def : primary_key index_name(?) '(' name_with_opt_paren(s /,/) ')'
646 supertype => 'constraint',
647 name => $item{'index_name(?)'}[0],
648 type => 'primary_key',
653 unique_key_def : UNIQUE KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
656 supertype => 'constraint',
657 name => $item{'index_name(?)'}[0],
663 normal_index : KEY index_name(?) '(' name_with_opt_paren(s /,/) ')'
666 supertype => 'index',
668 name => $item{'index_name(?)'}[0],
673 fulltext_index : /fulltext/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
676 supertype => 'index',
678 name => $item{'index_name(?)'}[0],
683 spatial_index : /spatial/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
686 supertype => 'index',
688 name => $item{'index_name(?)'}[0],
693 name_with_opt_paren : NAME parens_value_list(s?)
694 { $item[2][0] ? "$item[1]($item[2][0][0])" : $item[1] }
698 KEY : /key/i | /index/i
700 table_option : /comment/i /=/ /'.*?'/
702 my $comment = $item[3];
705 $return = { comment => $comment };
707 | /(default )?(charset|character set)/i /\s*=?\s*/ WORD
709 $return = { 'CHARACTER SET' => $item[3] };
713 $return = { 'COLLATE' => $item[2] }
715 | /union/i /\s*=\s*/ '(' table_name(s /,/) ')'
717 $return = { $item[1] => $item[4] };
719 | WORD /\s*=\s*/ WORD
721 $return = { $item[1] => $item[3] };
732 TEMPORARY : /temporary/i
744 NAME : BACKTICK /[^`]+/ BACKTICK
749 VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/
753 # remove leading/trailing quotes
755 $val =~ s/^['"]|['"]$//g;
761 CURRENT_TIMESTAMP : /current_timestamp(\(\))?/i
763 { 'CURRENT_TIMESTAMP' }
767 # -------------------------------------------------------------------
769 my ( $translator, $data ) = @_;
770 my $parser = Parse::RecDescent->new($GRAMMAR);
771 local $::RD_TRACE = $translator->trace ? 1 : undef;
772 local $DEBUG = $translator->debug;
774 unless (defined $parser) {
775 return $translator->error("Error instantiating Parse::RecDescent ".
776 "instance: Bad grammer");
779 # Preprocess for MySQL-specific and not-before-version comments from mysqldump
781 parse_mysql_version ($translator->parser_args->{mysql_parser_version}, 'mysql')
782 || DEFAULT_PARSER_VERSION;
783 while ( $data =~ s#/\*!(\d{5})?(.*?)\*/#($1 && $1 > $parser_version ? '' : $2)#es ) {}
785 my $result = $parser->startrule($data);
786 return $translator->error( "Parse failed." ) unless defined $result;
787 warn "Parse result:".Dumper( $result ) if $DEBUG;
789 my $schema = $translator->schema;
790 $schema->name($result->{'database_name'}) if $result->{'database_name'};
793 $result->{'tables'}{ $a }{'order'}
795 $result->{'tables'}{ $b }{'order'}
796 } keys %{ $result->{'tables'} };
798 for my $table_name ( @tables ) {
799 my $tdata = $result->{tables}{ $table_name };
800 my $table = $schema->add_table(
801 name => $tdata->{'table_name'},
802 ) or die $schema->error;
804 $table->comments( $tdata->{'comments'} );
807 $tdata->{'fields'}->{$a}->{'order'}
809 $tdata->{'fields'}->{$b}->{'order'}
810 } keys %{ $tdata->{'fields'} };
812 for my $fname ( @fields ) {
813 my $fdata = $tdata->{'fields'}{ $fname };
814 my $field = $table->add_field(
815 name => $fdata->{'name'},
816 data_type => $fdata->{'data_type'},
817 size => $fdata->{'size'},
818 default_value => $fdata->{'default'},
819 is_auto_increment => $fdata->{'is_auto_inc'},
820 is_nullable => $fdata->{'null'},
821 comments => $fdata->{'comments'},
822 ) or die $table->error;
824 $table->primary_key( $field->name ) if $fdata->{'is_primary_key'};
826 for my $qual ( qw[ binary unsigned zerofill list collate ],
827 'character set', 'on update' ) {
828 if ( my $val = $fdata->{ $qual } || $fdata->{ uc $qual } ) {
829 next if ref $val eq 'ARRAY' && !@$val;
830 $field->extra( $qual, $val );
834 if ( $fdata->{'has_index'} ) {
838 fields => $fdata->{'name'},
839 ) or die $table->error;
842 if ( $fdata->{'is_unique'} ) {
843 $table->add_constraint(
846 fields => $fdata->{'name'},
847 ) or die $table->error;
850 for my $cdata ( @{ $fdata->{'constraints'} } ) {
851 next unless $cdata->{'type'} eq 'foreign_key';
852 $cdata->{'fields'} ||= [ $field->name ];
853 push @{ $tdata->{'constraints'} }, $cdata;
858 for my $idata ( @{ $tdata->{'indices'} || [] } ) {
859 my $index = $table->add_index(
860 name => $idata->{'name'},
861 type => uc $idata->{'type'},
862 fields => $idata->{'fields'},
863 ) or die $table->error;
866 if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
868 my @ignore_opts = $translator->parser_args->{ignore_opts}?split(/,/,$translator->parser_args->{ignore_opts}):();
870 my $ignores = { map { $_ => 1 } @ignore_opts };
871 foreach my $option (@options) {
872 # make sure the option isn't in ignore list
873 my ($option_key) = keys %$option;
874 push(@cleaned_options, $option) unless (exists $ignores->{$option_key});
877 @cleaned_options = @options;
879 $table->options( \@cleaned_options ) or die $table->error;
882 for my $cdata ( @{ $tdata->{'constraints'} || [] } ) {
883 my $constraint = $table->add_constraint(
884 name => $cdata->{'name'},
885 type => $cdata->{'type'},
886 fields => $cdata->{'fields'},
887 reference_table => $cdata->{'reference_table'},
888 reference_fields => $cdata->{'reference_fields'},
889 match_type => $cdata->{'match_type'} || '',
890 on_delete => $cdata->{'on_delete'} || $cdata->{'on_delete_do'},
891 on_update => $cdata->{'on_update'} || $cdata->{'on_update_do'},
892 ) or die $table->error;
895 # After the constrains and PK/idxs have been created, we normalize fields
896 normalize_field($_) for $table->get_fields;
899 my @procedures = sort {
900 $result->{procedures}->{ $a }->{'order'} <=> $result->{procedures}->{ $b }->{'order'}
901 } keys %{ $result->{procedures} };
902 foreach my $proc_name (@procedures) {
903 $schema->add_procedure(
905 owner => $result->{procedures}->{$proc_name}->{owner},
906 sql => $result->{procedures}->{$proc_name}->{sql},
911 $result->{views}->{ $a }->{'order'} <=> $result->{views}->{ $b }->{'order'}
912 } keys %{ $result->{views} };
913 foreach my $view_name (keys %{ $result->{views} }) {
916 sql => $result->{views}->{$view_name}->{sql},
923 # Takes a field, and returns
924 sub normalize_field {
926 my ($size, $type, $list, $changed) = @_;
928 $size = $field->size;
929 $type = $field->data_type;
930 $list = $field->extra->{list} || [];
932 if ( !ref $size && $size eq 0 ) {
933 if ( lc $type eq 'tinyint' ) {
934 $changed = $size != 4;
937 elsif ( lc $type eq 'smallint' ) {
938 $changed = $size != 6;
941 elsif ( lc $type eq 'mediumint' ) {
942 $changed = $size != 9;
945 elsif ( $type =~ /^int(eger)?$/i ) {
946 $changed = $size != 11 || $type ne 'int';
950 elsif ( lc $type eq 'bigint' ) {
951 $changed = $size != 20;
954 elsif ( lc $type =~ /(float|double|decimal|numeric|real|fixed|dec)/ ) {
955 my $old_size = (ref $size || '') eq 'ARRAY' ? $size : [];
956 $changed = @$old_size != 2 || $old_size->[0] != 8 || $old_size->[1] != 2;
961 if ( $type =~ /^tiny(text|blob)$/i ) {
962 $changed = $size != 255;
965 elsif ( $type =~ /^(blob|text)$/i ) {
966 $changed = $size != 65_535;
969 elsif ( $type =~ /^medium(blob|text)$/i ) {
970 $changed = $size != 16_777_215;
973 elsif ( $type =~ /^long(blob|text)$/i ) {
974 $changed = $size != 4_294_967_295;
975 $size = 4_294_967_295;
977 if ( $field->data_type =~ /(set|enum)/i && !$field->size ) {
978 my %extra = $field->extra;
980 for my $len ( map { length } @{ $extra{'list'} || [] } ) {
981 $longest = $len if $len > $longest;
984 $size = $longest if $longest;
989 # We only want to clone the field, not *everything*
990 { local $field->{table} = undef;
991 $field->parsed_field(dclone($field));
992 $field->parsed_field->{table} = $field->table;
995 $field->data_type($type);
996 $field->sql_data_type( $type_mapping{lc $type} ) if exists $type_mapping{lc $type};
997 $field->extra->{list} = $list if @$list;
1004 # -------------------------------------------------------------------
1005 # Where man is not nature is barren.
1007 # -------------------------------------------------------------------
1013 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>,
1014 Chris Mungall E<lt>cjm@fruitfly.orgE<gt>.
1018 Parse::RecDescent, SQL::Translator::Schema.