Subject: | bug in enum_vals() |
If you have really ugly terms in an enum description (with apostraphes or commas), then the enum description parsing can break. Here's patches (diff -u) to add a failing test to mysql.t, and to fix mysql.pm:
$ cat mysql.t.diff
--- t/mysql.t Tue Apr 5 17:31:57 2005
+++ t/mysql.t.new Tue Apr 5 17:29:58 2005
@@ -32,7 +32,7 @@
Name VARCHAR(50) NOT NULL DEFAULT '',
val SMALLINT UNSIGNED NOT NULL DEFAULT 'A',
mydate TIMESTAMP NOT NULL,
- Myvals ENUM('foo', 'bar')
+ Myvals ENUM('foo', 'bar', 'baz''s, barf')
});
__PACKAGE__->set_up_table;
__PACKAGE__->autoinflate(dates => 'Time::Piece') if $HAVE_TP;
@@ -76,7 +76,7 @@
like $type, qr/^enum/i, "Myvals is an enum";
my @vals = sort Foo->enum_vals('Myvals');
-is_deeply \@vals, [qw/bar foo/], "Enum vals OK";
+is_deeply \@vals, [('bar', "baz's, barf", 'foo')], "Enum vals OK";
eval { Foo->enum_vals('mydate') };
ok $@, $@;
$ cat mysql.pm.diff
--- /usr/local/lib/perl5/site_perl/5.8.6/Class/DBI/mysql.pm Sat Feb 28 10:19:47 2004
+++ lib/Class/DBI/mysql.pm Tue Apr 5 17:27:53 2005
@@ -185,9 +185,8 @@
my $class = shift;
my $col = shift or die "Need a column for enum_vals";
my $series = $class->_column_info->{$col}->{type};
- $series =~ /enum\((.*?)\)/ or die "$col is not an ENUM column";
- (my $enum = $1) =~ s/'//g;
- return split /,/, $enum;
+ ( my $enum ) = $series =~ /enum\('(.*?)'\)/ or die "$col is not an ENUM column";
+ return map { s/''/'/g; $_ } split( "','", $enum );
}
=head2 retrieve_random