DBSchema::DBD::mysql NAME vs NAME_lc patch from Ralf Hack, closes: CPAN#16715.
[DBIx-DBSchema.git] / DBSchema / DBD / mysql.pm
index 08c457b..924c309 100644 (file)
@@ -1,9 +1,18 @@
 package DBIx::DBSchema::DBD::mysql;
 
 use strict;
-use vars qw($VERSION);
+use vars qw($VERSION @ISA %typemap);
+use DBIx::DBSchema::DBD;
 
-$VERSION = '0.01';
+$VERSION = '0.05';
+@ISA = qw(DBIx::DBSchema::DBD);
+
+%typemap = (
+  'TIMESTAMP'      => 'DATETIME',
+  'SERIAL'         => 'INTEGER',
+  'BOOL'           => 'TINYINT',
+  'LONG VARBINARY' => 'LONGBLOB',
+);
 
 =head1 NAME
 
@@ -25,14 +34,25 @@ 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);
-    [ $_->{'Field'}, $type, $_->{'Null'}, $length ]
+    [
+      $_->{'Field'},
+      $type,
+      $_->{'Null'},
+      $length,
+      $_->{'Default'},
+      $_->{'Extra'}
+    ]
   } @{ $sth->fetchall_arrayref( {} ) };
+  $dbh->{FetchHashKeyName}=$oldkhv;
+  @r;
 }
 
 #sub primary_key {
@@ -67,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;
@@ -82,6 +104,7 @@ sub _show_index {
       push @{ $unique{ $row->{'Key_name'} } }, $row->{'Column_name'};
     }
   }
+  $dbh->{FetchHashKeyName}=$oldkhv;
 
   ( $pkey, \%unique, \%index );
 }