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',
17 DBIx::DBSchema::DBD::mysql - MySQL native driver for DBIx::DBSchema
24 $dbh = DBI->connect('dbi:mysql:database', 'user', 'pass');
25 $schema = new_native DBIx::DBSchema $dbh;
29 This module implements a MySQL-native driver for DBIx::DBSchema.
34 my($proto, $dbh, $table ) = @_;
35 my $sth = $dbh->prepare("SHOW COLUMNS FROM $table") or die $dbh->errstr;
36 $sth->execute or die $sth->errstr;
38 $_->{'Type'} =~ /^(\w+)\(?([\d\,]+)?\)?( unsigned)?$/
39 or die "Illegal type: ". $_->{'Type'}. "\n";
40 my($type, $length) = ($1, $2);
49 } @{ $sth->fetchall_arrayref( {} ) };
53 # my($proto, $dbh, $table ) = @_;
54 # my $primary_key = '';
55 # my $sth = $dbh->prepare("SHOW INDEX FROM $table")
56 # or die $dbh->errstr;
57 # $sth->execute or die $sth->errstr;
58 # my @pkey = map { $_->{'Column_name'} } grep {
59 # $_->{'Key_name'} eq "PRIMARY"
60 # } @{ $sth->fetchall_arrayref( {} ) };
61 # scalar(@pkey) ? $pkey[0] : '';
65 my($proto, $dbh, $table) = @_;
66 my($pkey, $unique_href, $index_href) = $proto->_show_index($dbh, $table);
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 $sth = $dbh->prepare("SHOW INDEX FROM $table")
86 $sth->execute or die $sth->errstr;
90 foreach my $row ( @{ $sth->fetchall_arrayref({}) } ) {
91 if ( $row->{'Key_name'} eq 'PRIMARY' ) {
92 $pkey = $row->{'Column_name'};
93 } elsif ( $row->{'Non_unique'} ) { #index
94 push @{ $index{ $row->{'Key_name'} } }, $row->{'Column_name'};
96 push @{ $unique{ $row->{'Key_name'} } }, $row->{'Column_name'};
100 ( $pkey, \%unique, \%index );
105 Ivan Kohler <ivan-dbix-dbschema@420.am>
109 Copyright (c) 2000 Ivan Kohler
110 Copyright (c) 2000 Mail Abuse Prevention System LLC
112 This program is free software; you can redistribute it and/or modify it under
113 the same terms as Perl itself.
119 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>, L<DBI::DBD>