1 package DBIx::DBSchema::DBD::mysql;
4 use vars qw($VERSION @ISA %typemap);
5 use DBIx::DBSchema::DBD;
8 @ISA = qw(DBIx::DBSchema::DBD);
11 'TIMESTAMP' => 'DATETIME',
12 'SERIAL' => 'INTEGER',
14 'LONG VARBINARY' => 'LONGBLOB',
19 DBIx::DBSchema::DBD::mysql - MySQL native driver for DBIx::DBSchema
26 $dbh = DBI->connect('dbi:mysql:database', 'user', 'pass');
27 $schema = new_native DBIx::DBSchema $dbh;
31 This module implements a MySQL-native driver for DBIx::DBSchema.
36 my($proto, $dbh, $table ) = @_;
37 my $oldkhv=$dbh->{FetchHashKeyName};
38 $dbh->{FetchHashKeyName}="NAME";
39 my $sth = $dbh->prepare("SHOW COLUMNS FROM $table") or die $dbh->errstr;
40 $sth->execute or die $sth->errstr;
42 $_->{'Type'} =~ /^(\w+)\(?([^)]+)?\)?( \d+)?$/
43 or die "Illegal type: ". $_->{'Type'}. "\n";
44 my($type, $length) = ($1, $2);
53 } @{ $sth->fetchall_arrayref( {} ) };
54 $dbh->{FetchHashKeyName}=$oldkhv;
59 # my($proto, $dbh, $table ) = @_;
60 # my $primary_key = '';
61 # my $sth = $dbh->prepare("SHOW INDEX FROM $table")
62 # or die $dbh->errstr;
63 # $sth->execute or die $sth->errstr;
64 # my @pkey = map { $_->{'Column_name'} } grep {
65 # $_->{'Key_name'} eq "PRIMARY"
66 # } @{ $sth->fetchall_arrayref( {} ) };
67 # scalar(@pkey) ? $pkey[0] : '';
71 my($proto, $dbh, $table) = @_;
72 my($pkey, $unique_href, $index_href) = $proto->_show_index($dbh, $table);
77 my($proto, $dbh, $table) = @_;
78 my($pkey, $unique_href, $index_href) = $proto->_show_index($dbh, $table);
83 my($proto, $dbh, $table) = @_;
84 my($pkey, $unique_href, $index_href) = $proto->_show_index($dbh, $table);
89 my($proto, $dbh, $table ) = @_;
90 my $oldkhv=$dbh->{FetchHashKeyName};
91 $dbh->{FetchHashKeyName}="NAME";
92 my $sth = $dbh->prepare("SHOW INDEX FROM $table")
94 $sth->execute or die $sth->errstr;
98 foreach my $row ( @{ $sth->fetchall_arrayref({}) } ) {
99 if ( $row->{'Key_name'} eq 'PRIMARY' ) {
100 $pkey = $row->{'Column_name'};
101 } elsif ( $row->{'Non_unique'} ) { #index
102 push @{ $index{ $row->{'Key_name'} } }, $row->{'Column_name'};
104 push @{ $unique{ $row->{'Key_name'} } }, $row->{'Column_name'};
107 $dbh->{FetchHashKeyName}=$oldkhv;
109 ( $pkey, \%unique, \%index );
114 Ivan Kohler <ivan-dbix-dbschema@420.am>
118 Copyright (c) 2000 Ivan Kohler
119 Copyright (c) 2000 Mail Abuse Prevention System LLC
121 This program is free software; you can redistribute it and/or modify it under
122 the same terms as Perl itself.
128 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>, L<DBI::DBD>