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 = ();
164 @EXPORT_OK = qw(parse);
166 # Enable warnings within the Parse::RecDescent module.
167 $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
168 $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.
169 $::RD_HINT = 1; # Give out hints to help fix problems.
171 use constant DEFAULT_PARSER_VERSION => 30000;
173 $GRAMMAR = << 'END_OF_GRAMMAR';
176 my ( $database_name, %tables, $table_order, @table_comments, %views,
177 $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 {
189 database_name => $database_name,
192 procedures => \%procedures,
209 use : /use/i WORD "$delimiter"
211 $database_name = $item[2];
212 @table_comments = ();
215 set : /set/i /[^;]+/ "$delimiter"
216 { @table_comments = () }
218 drop : /drop/i TABLE /[^;]+/ "$delimiter"
220 drop : /drop/i WORD(s) "$delimiter"
221 { @table_comments = () }
224 # MySQL strings, unlike common SQL strings, can be double-quoted or
225 # single-quoted, and you can escape the delmiters by doubling (but only the
226 # delimiter) or by backslashing.
228 /'(\\.|''|[^\\\'])*'/ |
229 /"(\\.|""|[^\\\"])*"/
230 # For reference, std sql str: /(?:(?:\')(?:[^\']*(?:(?:\'\')[^\']*)*)(?:\'))//
232 nonstring : /[^;\'"]+/
234 statement_body : string | nonstring
236 insert : /insert/i statement_body(s?) "$delimiter"
238 delimiter : /delimiter/i /[\S]+/
239 { $delimiter = $item[2] }
241 empty_statement : "$delimiter"
243 alter : ALTER TABLE table_name alter_specification(s /,/) "$delimiter"
245 my $table_name = $item{'table_name'};
246 die "Cannot ALTER table '$table_name'; it does not exist"
247 unless $tables{ $table_name };
248 for my $definition ( @{ $item[4] } ) {
249 $definition->{'extra'}->{'alter'} = 1;
250 push @{ $tables{ $table_name }{'constraints'} }, $definition;
254 alter_specification : ADD foreign_key_def
255 { $return = $item[2] }
257 create : CREATE /database/i WORD "$delimiter"
258 { @table_comments = () }
260 create : CREATE TEMPORARY(?) TABLE opt_if_not_exists(?) table_name '(' create_definition(s /,/) /(,\s*)?\)/ table_option(s?) "$delimiter"
262 my $table_name = $item{'table_name'};
263 $tables{ $table_name }{'order'} = ++$table_order;
264 $tables{ $table_name }{'table_name'} = $table_name;
266 if ( @table_comments ) {
267 $tables{ $table_name }{'comments'} = [ @table_comments ];
268 @table_comments = ();
272 for my $definition ( @{ $item[7] } ) {
273 if ( $definition->{'supertype'} eq 'field' ) {
274 my $field_name = $definition->{'name'};
275 $tables{ $table_name }{'fields'}{ $field_name } =
276 { %$definition, order => $i };
279 if ( $definition->{'is_primary_key'} ) {
280 push @{ $tables{ $table_name }{'constraints'} },
282 type => 'primary_key',
283 fields => [ $field_name ],
288 elsif ( $definition->{'supertype'} eq 'constraint' ) {
289 push @{ $tables{ $table_name }{'constraints'} }, $definition;
291 elsif ( $definition->{'supertype'} eq 'index' ) {
292 push @{ $tables{ $table_name }{'indices'} }, $definition;
296 if ( my @options = @{ $item{'table_option(s?)'} } ) {
297 for my $option ( @options ) {
298 my ( $key, $value ) = each %$option;
299 if ( $key eq 'comment' ) {
300 push @{ $tables{ $table_name }{'comments'} }, $value;
303 push @{ $tables{ $table_name }{'table_options'} }, $option;
311 opt_if_not_exists : /if not exists/i
313 create : CREATE UNIQUE(?) /(index|key)/i index_name /on/i table_name '(' field_name(s /,/) ')' "$delimiter"
315 @table_comments = ();
316 push @{ $tables{ $item{'table_name'} }{'indices'} },
319 type => $item[2][0] ? 'unique' : 'normal',
325 create : CREATE /trigger/i NAME not_delimiter "$delimiter"
327 @table_comments = ();
330 create : CREATE PROCEDURE NAME not_delimiter "$delimiter"
332 @table_comments = ();
333 my $func_name = $item[3];
335 my $sql = "$item[1] $item[2] $item[3] $item[4]";
337 $procedures{ $func_name }{'order'} = ++$proc_order;
338 $procedures{ $func_name }{'name'} = $func_name;
339 $procedures{ $func_name }{'owner'} = $owner;
340 $procedures{ $func_name }{'sql'} = $sql;
343 PROCEDURE : /procedure/i
346 create : CREATE replace(?) algorithm(?) /view/i NAME not_delimiter "$delimiter"
348 @table_comments = ();
349 my $view_name = $item[5];
350 my $sql = join(q{ }, grep { defined and length } $item[1], $item[2]->[0], $item[3]->[0])
351 . " $item[4] $item[5] $item[6]";
353 # Hack to strip database from function calls in SQL
354 $sql =~ s#`\w+`\.(`\w+`\()##g;
356 $views{ $view_name }{'order'} = ++$view_order;
357 $views{ $view_name }{'name'} = $view_name;
358 $views{ $view_name }{'sql'} = $sql;
361 replace : /or replace/i
363 algorithm : /algorithm/i /=/ WORD
365 $return = "$item[1]=$item[3]";
368 not_delimiter : /.*?(?=$delimiter)/is
370 create_definition : constraint
376 comment : /^\s*(?:#|-{2}).*\n/
378 my $comment = $item[1];
379 $comment =~ s/^\s*(#|--)\s*//;
380 $comment =~ s/\s*$//;
384 comment : /\/\*/ /.*?\*\//s
386 my $comment = $item[2];
387 $comment = substr($comment, 0, -2);
388 $comment =~ s/^\s*|\s*$//g;
392 field_comment : /^\s*(?:#|-{2}).*\n/
394 my $comment = $item[1];
395 $comment =~ s/^\s*(#|--)\s*//;
396 $comment =~ s/\s*$//;
401 field_comment2 : /comment/i /'.*?'/
403 my $comment = $item[2];
411 field : field_comment(s?) field_name data_type field_qualifier(s?) field_comment2(?) reference_definition(?) on_update(?) field_comment(s?)
413 my %qualifiers = map { %$_ } @{ $item{'field_qualifier(s?)'} || [] };
414 if ( my @type_quals = @{ $item{'data_type'}{'qualifiers'} || [] } ) {
415 $qualifiers{ $_ } = 1 for @type_quals;
418 my $null = defined $qualifiers{'not_null'}
419 ? $qualifiers{'not_null'} : 1;
420 delete $qualifiers{'not_null'};
422 my @comments = ( @{ $item[1] }, @{ $item[5] }, @{ $item[8] } );
425 supertype => 'field',
426 name => $item{'field_name'},
427 data_type => $item{'data_type'}{'type'},
428 size => $item{'data_type'}{'size'},
429 list => $item{'data_type'}{'list'},
431 constraints => $item{'reference_definition(?)'},
432 comments => [ @comments ],
438 field_qualifier : not_null
441 null => $item{'not_null'},
445 field_qualifier : default_val
448 default => $item{'default_val'},
452 field_qualifier : auto_inc
455 is_auto_inc => $item{'auto_inc'},
459 field_qualifier : primary_key
462 is_primary_key => $item{'primary_key'},
466 field_qualifier : unsigned
469 is_unsigned => $item{'unsigned'},
473 field_qualifier : /character set/i WORD
476 'CHARACTER SET' => $item[2],
480 field_qualifier : /collate/i WORD
487 field_qualifier : /on update/i CURRENT_TIMESTAMP
490 'ON UPDATE' => $item[2],
494 field_qualifier : /unique/i KEY(?)
501 field_qualifier : KEY
508 reference_definition : /references/i table_name parens_field_list(?) match_type(?) on_delete(?) on_update(?)
511 type => 'foreign_key',
512 reference_table => $item[2],
513 reference_fields => $item[3][0],
514 match_type => $item[4][0],
515 on_delete => $item[5][0],
516 on_update => $item[6][0],
520 match_type : /match full/i { 'full' }
522 /match partial/i { 'partial' }
524 on_delete : /on delete/i reference_option
528 /on update/i 'CURRENT_TIMESTAMP'
531 /on update/i reference_option
534 reference_option: /restrict/i |
552 data_type : WORD parens_value_list(s?) type_qualifier(s?)
555 my $size; # field size, applicable only to non-set fields
556 my $list; # set list, applicable only to sets (duh)
558 if ( uc($type) =~ /^(SET|ENUM)$/ ) {
572 qualifiers => $item[3],
576 parens_field_list : '(' field_name(s /,/) ')'
579 parens_value_list : '(' VALUE(s /,/) ')'
582 type_qualifier : /(BINARY|UNSIGNED|ZEROFILL)/i
587 create_index : /create/i /index/i
589 not_null : /not/i /null/i
595 unsigned : /unsigned/i { $return = 0 }
597 #default_val : /default/i /(?:')?[\s\w\d:.-]*(?:')?/
599 # $item[2] =~ s/'//g;
600 # $return = $item[2];
604 /default/i 'CURRENT_TIMESTAMP'
609 /default/i /'(?:.*?(?:\\'|''))*.*?'|(?:')?[\w\d:.-]*(?:')?/
611 $item[2] =~ s/^\s*'|'\s*$//g;
615 auto_inc : /auto_increment/i { 1 }
617 primary_key : /primary/i /key/i { 1 }
619 constraint : primary_key_def
624 foreign_key_def : foreign_key_def_begin parens_field_list reference_definition
627 supertype => 'constraint',
628 type => 'foreign_key',
631 %{ $item{'reference_definition'} },
635 foreign_key_def_begin : /constraint/i /foreign key/i WORD
636 { $return = $item[3] }
638 /constraint/i NAME /foreign key/i
639 { $return = $item[2] }
641 /constraint/i /foreign key/i
645 { $return = $item[2] }
650 primary_key_def : primary_key index_name(?) '(' name_with_opt_paren(s /,/) ')'
653 supertype => 'constraint',
654 name => $item{'index_name(?)'}[0],
655 type => 'primary_key',
660 unique_key_def : UNIQUE KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
663 supertype => 'constraint',
664 name => $item{'index_name(?)'}[0],
670 normal_index : KEY index_name(?) '(' name_with_opt_paren(s /,/) ')'
673 supertype => 'index',
675 name => $item{'index_name(?)'}[0],
680 fulltext_index : /fulltext/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
683 supertype => 'index',
685 name => $item{'index_name(?)'}[0],
690 spatial_index : /spatial/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
693 supertype => 'index',
695 name => $item{'index_name(?)'}[0],
700 name_with_opt_paren : NAME parens_value_list(s?)
701 { $item[2][0] ? "$item[1]($item[2][0][0])" : $item[1] }
705 KEY : /key/i | /index/i
707 table_option : /comment/i /=/ /'.*?'/
709 my $comment = $item[3];
712 $return = { comment => $comment };
714 | /(default )?(charset|character set)/i /\s*=?\s*/ WORD
716 $return = { 'CHARACTER SET' => $item[3] };
720 $return = { 'COLLATE' => $item[2] }
722 | /union/i /\s*=\s*/ '(' table_name(s /,/) ')'
724 $return = { $item[1] => $item[4] };
726 | WORD /\s*=\s*/ MAYBE_QUOTED_WORD
728 $return = { $item[1] => $item[3] };
731 MAYBE_QUOTED_WORD: /\w+/
745 TEMPORARY : /temporary/i
759 NAME : BACKTICK /[^`]+/ BACKTICK
761 | DOUBLE_QUOTE /[^"]+/ DOUBLE_QUOTE
766 VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/
770 # remove leading/trailing quotes
772 $val =~ s/^['"]|['"]$//g;
778 CURRENT_TIMESTAMP : /current_timestamp(\(\))?/i
780 { 'CURRENT_TIMESTAMP' }
784 # -------------------------------------------------------------------
786 my ( $translator, $data ) = @_;
787 my $parser = Parse::RecDescent->new($GRAMMAR);
788 local $::RD_TRACE = $translator->trace ? 1 : undef;
789 local $DEBUG = $translator->debug;
791 unless (defined $parser) {
792 return $translator->error("Error instantiating Parse::RecDescent ".
793 "instance: Bad grammer");
796 # Preprocess for MySQL-specific and not-before-version comments
798 my $parser_version = parse_mysql_version(
799 $translator->parser_args->{mysql_parser_version}, 'mysql'
800 ) || DEFAULT_PARSER_VERSION;
803 s#/\*!(\d{5})?(.*?)\*/#($1 && $1 > $parser_version ? '' : $2)#es
805 # do nothing; is there a better way to write this? -- ky
808 my $result = $parser->startrule($data);
809 return $translator->error( "Parse failed." ) unless defined $result;
810 warn "Parse result:".Dumper( $result ) if $DEBUG;
812 my $schema = $translator->schema;
813 $schema->name($result->{'database_name'}) if $result->{'database_name'};
816 $result->{'tables'}{ $a }{'order'}
818 $result->{'tables'}{ $b }{'order'}
819 } keys %{ $result->{'tables'} };
821 for my $table_name ( @tables ) {
822 my $tdata = $result->{tables}{ $table_name };
823 my $table = $schema->add_table(
824 name => $tdata->{'table_name'},
825 ) or die $schema->error;
827 $table->comments( $tdata->{'comments'} );
830 $tdata->{'fields'}->{$a}->{'order'}
832 $tdata->{'fields'}->{$b}->{'order'}
833 } keys %{ $tdata->{'fields'} };
835 for my $fname ( @fields ) {
836 my $fdata = $tdata->{'fields'}{ $fname };
837 my $field = $table->add_field(
838 name => $fdata->{'name'},
839 data_type => $fdata->{'data_type'},
840 size => $fdata->{'size'},
841 default_value => $fdata->{'default'},
842 is_auto_increment => $fdata->{'is_auto_inc'},
843 is_nullable => $fdata->{'null'},
844 comments => $fdata->{'comments'},
845 ) or die $table->error;
847 $table->primary_key( $field->name ) if $fdata->{'is_primary_key'};
849 for my $qual ( qw[ binary unsigned zerofill list collate ],
850 'character set', 'on update' ) {
851 if ( my $val = $fdata->{ $qual } || $fdata->{ uc $qual } ) {
852 next if ref $val eq 'ARRAY' && !@$val;
853 $field->extra( $qual, $val );
857 if ( $fdata->{'has_index'} ) {
861 fields => $fdata->{'name'},
862 ) or die $table->error;
865 if ( $fdata->{'is_unique'} ) {
866 $table->add_constraint(
869 fields => $fdata->{'name'},
870 ) or die $table->error;
873 for my $cdata ( @{ $fdata->{'constraints'} } ) {
874 next unless $cdata->{'type'} eq 'foreign_key';
875 $cdata->{'fields'} ||= [ $field->name ];
876 push @{ $tdata->{'constraints'} }, $cdata;
881 for my $idata ( @{ $tdata->{'indices'} || [] } ) {
882 my $index = $table->add_index(
883 name => $idata->{'name'},
884 type => uc $idata->{'type'},
885 fields => $idata->{'fields'},
886 ) or die $table->error;
889 if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
891 my @ignore_opts = $translator->parser_args->{'ignore_opts'}
892 ? split( /,/, $translator->parser_args->{'ignore_opts'} )
895 my $ignores = { map { $_ => 1 } @ignore_opts };
896 foreach my $option (@options) {
897 # make sure the option isn't in ignore list
898 my ($option_key) = keys %$option;
899 if ( !exists $ignores->{$option_key} ) {
900 push @cleaned_options, $option;
904 @cleaned_options = @options;
906 $table->options( \@cleaned_options ) or die $table->error;
909 for my $cdata ( @{ $tdata->{'constraints'} || [] } ) {
910 my $constraint = $table->add_constraint(
911 name => $cdata->{'name'},
912 type => $cdata->{'type'},
913 fields => $cdata->{'fields'},
914 reference_table => $cdata->{'reference_table'},
915 reference_fields => $cdata->{'reference_fields'},
916 match_type => $cdata->{'match_type'} || '',
917 on_delete => $cdata->{'on_delete'}
918 || $cdata->{'on_delete_do'},
919 on_update => $cdata->{'on_update'}
920 || $cdata->{'on_update_do'},
921 ) or die $table->error;
924 # After the constrains and PK/idxs have been created,
925 # we normalize fields
926 normalize_field($_) for $table->get_fields;
929 my @procedures = sort {
930 $result->{procedures}->{ $a }->{'order'}
932 $result->{procedures}->{ $b }->{'order'}
933 } keys %{ $result->{procedures} };
935 for my $proc_name ( @procedures ) {
936 $schema->add_procedure(
938 owner => $result->{procedures}->{$proc_name}->{owner},
939 sql => $result->{procedures}->{$proc_name}->{sql},
944 $result->{views}->{ $a }->{'order'}
946 $result->{views}->{ $b }->{'order'}
947 } keys %{ $result->{views} };
949 for my $view_name ( keys %{ $result->{'views'} } ) {
952 sql => $result->{'views'}->{$view_name}->{sql},
959 # Takes a field, and returns
960 sub normalize_field {
962 my ($size, $type, $list, $changed) = @_;
964 $size = $field->size;
965 $type = $field->data_type;
966 $list = $field->extra->{list} || [];
968 if ( !ref $size && $size eq 0 ) {
969 if ( lc $type eq 'tinyint' ) {
970 $changed = $size != 4;
973 elsif ( lc $type eq 'smallint' ) {
974 $changed = $size != 6;
977 elsif ( lc $type eq 'mediumint' ) {
978 $changed = $size != 9;
981 elsif ( $type =~ /^int(eger)?$/i ) {
982 $changed = $size != 11 || $type ne 'int';
986 elsif ( lc $type eq 'bigint' ) {
987 $changed = $size != 20;
990 elsif ( lc $type =~ /(float|double|decimal|numeric|real|fixed|dec)/ ) {
991 my $old_size = (ref $size || '') eq 'ARRAY' ? $size : [];
992 $changed = @$old_size != 2
993 || $old_size->[0] != 8
994 || $old_size->[1] != 2;
999 if ( $type =~ /^tiny(text|blob)$/i ) {
1000 $changed = $size != 255;
1003 elsif ( $type =~ /^(blob|text)$/i ) {
1004 $changed = $size != 65_535;
1007 elsif ( $type =~ /^medium(blob|text)$/i ) {
1008 $changed = $size != 16_777_215;
1011 elsif ( $type =~ /^long(blob|text)$/i ) {
1012 $changed = $size != 4_294_967_295;
1013 $size = 4_294_967_295;
1016 if ( $field->data_type =~ /(set|enum)/i && !$field->size ) {
1017 my %extra = $field->extra;
1019 for my $len ( map { length } @{ $extra{'list'} || [] } ) {
1020 $longest = $len if $len > $longest;
1023 $size = $longest if $longest;
1028 # We only want to clone the field, not *everything*
1030 local $field->{table} = undef;
1031 $field->parsed_field( dclone( $field ) );
1032 $field->parsed_field->{table} = $field->table;
1034 $field->size( $size );
1035 $field->data_type( $type );
1036 $field->sql_data_type( $type_mapping{ lc $type } )
1037 if exists $type_mapping{ lc $type };
1038 $field->extra->{list} = $list if @$list;
1044 # -------------------------------------------------------------------
1045 # Where man is not nature is barren.
1047 # -------------------------------------------------------------------
1053 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>,
1054 Chris Mungall E<lt>cjm@fruitfly.orgE<gt>.
1058 Parse::RecDescent, SQL::Translator::Schema.