Subject: | DBI-MySQL parser doesn't handle ENUM well enough for PostgreSQL producer |
Although it looks like the "fix" in 0.08 was to comment out the
functionality for handling MySQL's ENUM type in the PostgreSQL producer,
I find that I need this functionality.
I have included a diff against .07 which adds the parsing functionality
to the DBI::MySQL parser, which works with the .07 PostgreSQL producer.
I have not tested any other combinations, nor have I attempted to work
around any other shortcomings.
Subject: | DBI-MySQL.pm.diff |
--- /usr/share/perl5/SQL/Translator/Parser/DBI/MySQL.pm 2006-07-04 14:42:10.000000000 -0700
+++ Parser/DBI/MySQL.pm 2007-07-31 12:08:50.000000000 -0700
@@ -70,13 +70,32 @@
my $default = $col->{'default'};
my $extra = $col->{'extra'};
- my ( $data_type, $size, $char_set );
+ my ( $data_type, $size, $char_set, @list );
#
+ # set/enum datatype = "SET('a','b')"
+ # or "ENUM('ab','xyz')"
+ #
+ if ( $type =~ m{
+ (set|enum) # data type
+ \( # open paren
+ ([^)]+) # list items
+ \) # close paren
+ }x
+ ) {
+ $data_type = $1;
+ @list = (@list, split(",",$2));
+ for (@list) {
+ s/^\'//;
+ s/\'$//;
+ $size = length if !$size || length > $size;
+ }
+ }
+ #
# Normal datatype = "int(11)"
# or "varchar(20) character set latin1"
#
- if ( $type =~ m{
+ elsif ( $type =~ m{
(\w+) # data type
\( # open paren
(\d+) # first number
@@ -111,6 +130,7 @@
is_auto_increment => $extra eq 'auto_increment',
is_nullable => $is_nullable,
comments => $extra,
+ extra => { 'list' => \@list },
) or die $table->error;
$table->primary_key( $field->name ) if $key eq 'PRI';