$sth->execute($db_schema, $tabname) or die;
my @cols = map { lc } map { @$_ } @{$sth->fetchall_arrayref};
- $sth->finish;
+ undef $sth;
$sth = $dbh->prepare(<<'SQL') or die;
SELECT kcu.COLNAME
my @pri = map { lc } map { @$_ } @{$sth->fetchall_arrayref};
- $sth->finish;
-
return ( \@cols, \@pri );
}
SQL
foreach my $table ( $class->tables ) {
- if ($sth->execute(uc $table)) {
- while(my $res = $sth->fetchrow_arrayref()) {
- my ($colcount, $other, $other_column, $column) =
- map { lc } @$res;
-
- my @self_cols = split(' ',$column);
- my @other_cols = split(' ',$other_column);
- if(@self_cols != $colcount || @other_cols != $colcount) {
- die "Column count discrepancy while getting rel info";
- }
-
- my %cond;
- for(my $i = 0; $i < @self_cols; $i++) {
- $cond{$other_cols[$i]} = $self_cols[$i];
- }
-
- eval { $class->_loader_make_relations ($table, $other, \%cond); };
- warn qq/\# belongs_to_many failed "$@"\n\n/
- if $@ && $class->_loader_debug;
+ next if ! $sth->execute(uc $table);
+ while(my $res = $sth->fetchrow_arrayref()) {
+ my ($colcount, $other, $other_column, $column) =
+ map { lc } @$res;
+
+ my @self_cols = split(' ',$column);
+ my @other_cols = split(' ',$other_column);
+ if(@self_cols != $colcount || @other_cols != $colcount) {
+ die "Column count discrepancy while getting rel info";
}
+
+ my %cond;
+ for(my $i = 0; $i < @self_cols; $i++) {
+ $cond{$other_cols[$i]} = $self_cols[$i];
+ }
+
+ eval { $class->_loader_make_relations ($table, $other, \%cond); };
+ warn qq/\# belongs_to_many failed "$@"\n\n/
+ if $@ && $class->_loader_debug;
}
}
require DBIx::Class::Core;
-__PACKAGE__->mk_classdata('_loader_data');
-__PACKAGE__->mk_classdata('_loader_debug' => 0);
+__PACKAGE__->mk_classaccessor('_loader_data');
+__PACKAGE__->mk_classaccessor('_loader_debug' => 0);
=head1 NAME
left_base => $left_base,
constraint => $args{constraint} || '.*',
exclude => $args{exclude},
- relationships => $args{relationships},
inflect => $args{inflect},
db_schema => $args{db_schema} || '',
drop_db_schema => $args{drop_db_schema},
warn qq/\### START DBIx::Class::Schema::Loader dump ###\n/
if $class->_loader_debug;
$class->_loader_load_classes;
- $class->_loader_relationships if $class->_loader_data->{relationships};
+ $class->_loader_relationships if $args{relationships};
warn qq/\### END DBIx::Class::Schema::Loader dump ###\n/
if $class->_loader_debug;
$class->storage->dbh->disconnect; # XXX this should be ->storage->disconnect later?
# Overload in your driver class
sub _loader_db_classes { croak "ABSTRACT METHOD" }
+# not a class method.
+sub _loader_stringify_hash {
+ my $href = shift;
+
+ return '{ ' .
+ join(q{, }, map("$_ => $href->{$_}", keys %$href))
+ . ' }';
+}
+
# Setup has_a and has_many relationships
sub _loader_make_relations {
- use Data::Dumper;
my ( $class, $table, $other, $cond ) = @_;
my $table_class = $class->_loader_find_table_class($table);
my $rev_cond = { reverse %$cond };
+ my $cond_printable = _loader_stringify_hash($cond)
+ if $class->_loader_debug;
+ my $rev_cond_printable = _loader_stringify_hash($rev_cond)
+ if $class->_loader_debug;
+
warn qq/\# Belongs_to relationship\n/ if $class->_loader_debug;
warn qq/$table_class->belongs_to( '$other_relname' => '$other_class',/
- . Dumper($cond)
- . qq/);\n\n/
+ . qq/$cond_printable);\n\n/
if $class->_loader_debug;
$table_class->belongs_to( $other_relname => $other_class, $cond);
warn qq/\# Has_many relationship\n/ if $class->_loader_debug;
warn qq/$other_class->has_many( '$table_relname' => '$table_class',/
- . Dumper($rev_cond)
+ . qq/$rev_cond_printable);\n\n/
. qq/);\n\n/
if $class->_loader_debug;
CREATE TABLE loader_test1 (
id $self->{auto_inc_pk},
dat VARCHAR(32)
- ) $self->{innodb};
+ ) $self->{innodb}
},
- q{ INSERT INTO loader_test1 (dat) VALUES('foo'); },
- q{ INSERT INTO loader_test1 (dat) VALUES('bar'); },
- q{ INSERT INTO loader_test1 (dat) VALUES('baz'); },
+ q{ INSERT INTO loader_test1 (dat) VALUES('foo') },
+ q{ INSERT INTO loader_test1 (dat) VALUES('bar') },
+ q{ INSERT INTO loader_test1 (dat) VALUES('baz') },
qq{
CREATE TABLE loader_test2 (
id $self->{auto_inc_pk},
dat VARCHAR(32)
- ) $self->{innodb};
+ ) $self->{innodb}
},
- q{ INSERT INTO loader_test2 (dat) VALUES('aaa'); },
- q{ INSERT INTO loader_test2 (dat) VALUES('bbb'); },
- q{ INSERT INTO loader_test2 (dat) VALUES('ccc'); },
- q{ INSERT INTO loader_test2 (dat) VALUES('ddd'); },
+ q{ INSERT INTO loader_test2 (dat) VALUES('aaa') },
+ q{ INSERT INTO loader_test2 (dat) VALUES('bbb') },
+ q{ INSERT INTO loader_test2 (dat) VALUES('ccc') },
+ q{ INSERT INTO loader_test2 (dat) VALUES('ddd') },
);
my @statements_reltests = (
CREATE TABLE loader_test3 (
id INTEGER NOT NULL PRIMARY KEY,
dat VARCHAR(32)
- ) $self->{innodb};
+ ) $self->{innodb}
},
- q{ INSERT INTO loader_test3 (id,dat) VALUES(1,'aaa'); },
- q{ INSERT INTO loader_test3 (id,dat) VALUES(2,'bbb'); },
- q{ INSERT INTO loader_test3 (id,dat) VALUES(3,'ccc'); },
- q{ INSERT INTO loader_test3 (id,dat) VALUES(4,'ddd'); },
+ q{ INSERT INTO loader_test3 (id,dat) VALUES(1,'aaa') },
+ q{ INSERT INTO loader_test3 (id,dat) VALUES(2,'bbb') },
+ q{ INSERT INTO loader_test3 (id,dat) VALUES(3,'ccc') },
+ q{ INSERT INTO loader_test3 (id,dat) VALUES(4,'ddd') },
qq{
CREATE TABLE loader_test4 (
fkid INTEGER NOT NULL,
dat VARCHAR(32),
FOREIGN KEY (fkid) REFERENCES loader_test3 (id)
- ) $self->{innodb};
+ ) $self->{innodb}
},
- q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(123,1,'aaa'); },
- q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(124,2,'bbb'); },
- q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(125,3,'ccc'); },
- q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(126,4,'ddd'); },
+ q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(123,1,'aaa') },
+ q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(124,2,'bbb') },
+ q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(125,3,'ccc') },
+ q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(126,4,'ddd') },
qq{
CREATE TABLE loader_test5 (
id2 INTEGER NOT NULL, -- , id2 INTEGER REFERENCES loader_test1,
dat VARCHAR(8),
PRIMARY KEY (id1,id2)
- ) $self->{innodb};
+ ) $self->{innodb}
},
- q{ INSERT INTO loader_test5 (id1,id2,dat) VALUES (1,1,'aaa'); },
+ q{ INSERT INTO loader_test5 (id1,id2,dat) VALUES (1,1,'aaa') },
qq{
CREATE TABLE loader_test6 (
dat VARCHAR(8),
FOREIGN KEY (loader_test2) REFERENCES loader_test2 (id),
FOREIGN KEY (id, id2 ) REFERENCES loader_test5 (id1,id2)
- ) $self->{innodb};
+ ) $self->{innodb}
},
(q{ INSERT INTO loader_test6 (id, id2,loader_test2,dat) } .
- q{ VALUES (1, 1,1,'aaa'); }),
+ q{ VALUES (1, 1,1,'aaa') }),
qq{
CREATE TABLE loader_test7 (
id INTEGER NOT NULL PRIMARY KEY,
id2 VARCHAR(8) NOT NULL UNIQUE,
dat VARCHAR(8)
- ) $self->{innodb};
+ ) $self->{innodb}
},
- q{ INSERT INTO loader_test7 (id,id2,dat) VALUES (1,'aaa','bbb'); },
+ q{ INSERT INTO loader_test7 (id,id2,dat) VALUES (1,'aaa','bbb') },
qq{
CREATE TABLE loader_test8 (
loader_test7 VARCHAR(8) NOT NULL,
dat VARCHAR(8),
FOREIGN KEY (loader_test7) REFERENCES loader_test7 (id2)
- ) $self->{innodb};
+ ) $self->{innodb}
},
(q{ INSERT INTO loader_test8 (id,loader_test7,dat) } .
- q{ VALUES (1,'aaa','bbb'); }),
+ q{ VALUES (1,'aaa','bbb') }),
qq{
CREATE TABLE loader_test9 (
loader_test9 VARCHAR(8) NOT NULL
- ) $self->{innodb};
+ ) $self->{innodb}
},
);
id10 $self->{auto_inc_pk},
subject VARCHAR(8),
loader_test11 INTEGER
- ) $self->{innodb};
+ ) $self->{innodb}
},
qq{
message VARCHAR(8) DEFAULT 'foo',
loader_test10 INTEGER,
FOREIGN KEY (loader_test10) REFERENCES loader_test10 (id10)
- ) $self->{innodb};
+ ) $self->{innodb}
},
(q{ ALTER TABLE loader_test10 ADD CONSTRAINT } .
q{ loader_test11_fk FOREIGN KEY (loader_test11) } .
- q{ REFERENCES loader_test11 (id11); }),
+ q{ REFERENCES loader_test11 (id11) }),
);
$self->drop_tables;