1 package DBIx::Class::Schema::Loader::mysql;
5 use base 'DBIx::Class::Schema::Loader::Generic';
10 DBIx::Class::Schema::Loader::mysql - DBIx::Schema::Class::Loader mysql Implementation.
15 use base qw/DBIx::Class::Schema::Loader/;
17 __PACKAGE__->load_from_connection(
18 dsn => "dbi:mysql:dbname",
27 See L<DBIx::Class::Schema::Loader>.
32 return qw/DBIx::Class::PK::Auto::MySQL/;
35 sub _load_relationships {
37 my @tables = $self->tables;
38 my $dbh = $self->schema->storage->dbh;
40 my $quoter = $dbh->get_info(29) || q{`};
42 foreach my $table (@tables) {
43 my $query = "SHOW CREATE TABLE ${table}";
44 my $sth = $dbh->prepare($query)
45 or die("Cannot get table definition: $table");
47 my $table_def = $sth->fetchrow_arrayref->[1] || '';
49 my (@reldata) = ($table_def =~ /CONSTRAINT `.*` FOREIGN KEY \(`(.*)`\) REFERENCES `(.*)` \(`(.*)`\)/ig);
51 while (scalar @reldata > 0) {
52 my $cols = shift @reldata;
53 my $f_table = shift @reldata;
54 my $f_cols = shift @reldata;
56 my @cols = map { s/$quoter//; $_ } split(/\s*,\s*/,$cols);
57 my @f_cols = map { s/$quoter//; $_ } split(/\s*,\s*/,$f_cols);
58 die "Mismatched column count in rel for $table => $f_table"
62 for(my $i = 0; $i < @cols; $i++) {
63 $cond->{$f_cols[$i]} = $cols[$i];
66 eval { $self->_make_cond_rel( $table, $f_table, $cond) };
67 warn qq/\# belongs_to_many failed "$@"\n\n/ if $@ && $self->debug;
76 my $dbh = $self->schema->storage->dbh;
78 my $quoter = $dbh->get_info(29) || q{`};
79 foreach my $table ( $dbh->tables ) {
80 $table =~ s/$quoter//g;
82 if $table =~ /\A(\w+)\z/;
88 my ( $self, $table ) = @_;
89 my $dbh = $self->schema->storage->dbh;
91 # MySQL 4.x doesn't support quoted tables
92 my $query = "DESCRIBE $table";
93 my $sth = $dbh->prepare($query) or die("Cannot get table status: $table");
96 while ( my $hash = $sth->fetchrow_hashref ) {
97 my ($col) = $hash->{Field} =~ /(\w+)/;
99 push @pri, $col if $hash->{Key} eq "PRI";
102 return ( \@cols, \@pri );
107 L<DBIx::Class::Schema::Loader>