1 package DBIx::DBSchema::DBD::mysql;
10 DBIx::DBSchema::DBD::mysql - MySQL native driver for DBIx::DBSchema
17 $dbh = DBI->connect('dbi:mysql:database', 'user', 'pass');
18 $schema = new_native DBIx::DBSchema $dbh;
22 This module implements a MySQL-native driver for DBIx::DBSchema.
27 my($proto, $dbh, $table ) = @_;
28 my $sth = $dbh->prepare("SHOW COLUMNS FROM $table") or die $dbh->errstr;
29 $sth->execute or die $sth->errstr;
31 $_->{'Type'} =~ /^(\w+)\(?([\d\,]+)?\)?( unsigned)?$/
32 or die "Illegal type: ". $_->{'Type'}. "\n";
33 my($type, $length) = ($1, $2);
34 [ $_->{'Field'}, $type, $_->{'Null'}, $length, $_->{'Extra'} ]
35 } @{ $sth->fetchall_arrayref( {} ) };
39 # my($proto, $dbh, $table ) = @_;
40 # my $primary_key = '';
41 # my $sth = $dbh->prepare("SHOW INDEX FROM $table")
42 # or die $dbh->errstr;
43 # $sth->execute or die $sth->errstr;
44 # my @pkey = map { $_->{'Column_name'} } grep {
45 # $_->{'Key_name'} eq "PRIMARY"
46 # } @{ $sth->fetchall_arrayref( {} ) };
47 # scalar(@pkey) ? $pkey[0] : '';
51 my($proto, $dbh, $table) = @_;
52 my($pkey, $unique_href, $index_href) = $proto->_show_index($dbh, $table);
57 my($proto, $dbh, $table) = @_;
58 my($pkey, $unique_href, $index_href) = $proto->_show_index($dbh, $table);
63 my($proto, $dbh, $table) = @_;
64 my($pkey, $unique_href, $index_href) = $proto->_show_index($dbh, $table);
69 my($proto, $dbh, $table ) = @_;
70 my $sth = $dbh->prepare("SHOW INDEX FROM $table")
72 $sth->execute or die $sth->errstr;
76 foreach my $row ( @{ $sth->fetchall_arrayref({}) } ) {
77 if ( $row->{'Key_name'} eq 'PRIMARY' ) {
78 $pkey = $row->{'Column_name'};
79 } elsif ( $row->{'Non_unique'} ) { #index
80 push @{ $index{ $row->{'Key_name'} } }, $row->{'Column_name'};
82 push @{ $unique{ $row->{'Key_name'} } }, $row->{'Column_name'};
86 ( $pkey, \%unique, \%index );
91 Ivan Kohler <ivan-dbix-dbschema@420.am>
95 Copyright (c) 2000 Ivan Kohler
96 Copyright (c) 2000 Mail Abuse Prevention System LLC
98 This program is free software; you can redistribute it and/or modify it under
99 the same terms as Perl itself.
105 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>, L<DBI::DBD>