DBSchema::DBD::mysql NAME vs NAME_lc patch from Ralf Hack, closes: CPAN#16715.
[DBIx-DBSchema.git] / DBSchema / DBD / mysql.pm
index 9fa7f80..924c309 100644 (file)
@@ -4,12 +4,14 @@ use strict;
 use vars qw($VERSION @ISA %typemap);
 use DBIx::DBSchema::DBD;
 
-$VERSION = '0.02';
+$VERSION = '0.05';
 @ISA = qw(DBIx::DBSchema::DBD);
 
 %typemap = (
-  'TIMESTAMP' => 'DATETIME',
-  'SERIAL'    => 'INTEGER',
+  'TIMESTAMP'      => 'DATETIME',
+  'SERIAL'         => 'INTEGER',
+  'BOOL'           => 'TINYINT',
+  'LONG VARBINARY' => 'LONGBLOB',
 );
 
 =head1 NAME
@@ -32,10 +34,12 @@ This module implements a MySQL-native driver for DBIx::DBSchema.
 
 sub columns {
   my($proto, $dbh, $table ) = @_;
+  my $oldkhv=$dbh->{FetchHashKeyName};
+  $dbh->{FetchHashKeyName}="NAME";
   my $sth = $dbh->prepare("SHOW COLUMNS FROM $table") or die $dbh->errstr;
   $sth->execute or die $sth->errstr;
-  map {
-    $_->{'Type'} =~ /^(\w+)\(?([\d\,]+)?\)?( unsigned)?$/
+  my @r = map {
+    $_->{'Type'} =~ /^(\w+)\(?([^)]+)?\)?( \d+)?$/
       or die "Illegal type: ". $_->{'Type'}. "\n";
     my($type, $length) = ($1, $2);
     [
@@ -47,6 +51,8 @@ sub columns {
       $_->{'Extra'}
     ]
   } @{ $sth->fetchall_arrayref( {} ) };
+  $dbh->{FetchHashKeyName}=$oldkhv;
+  @r;
 }
 
 #sub primary_key {
@@ -81,6 +87,8 @@ sub index {
 
 sub _show_index {
   my($proto, $dbh, $table ) = @_;
+  my $oldkhv=$dbh->{FetchHashKeyName};
+  $dbh->{FetchHashKeyName}="NAME";
   my $sth = $dbh->prepare("SHOW INDEX FROM $table")
     or die $dbh->errstr;
   $sth->execute or die $sth->errstr;
@@ -96,6 +104,7 @@ sub _show_index {
       push @{ $unique{ $row->{'Key_name'} } }, $row->{'Column_name'};
     }
   }
+  $dbh->{FetchHashKeyName}=$oldkhv;
 
   ( $pkey, \%unique, \%index );
 }