my $sth = $dbh->prepare($self->schema->storage->sql_maker->select($table, undef, \'1 = 0'));
$sth->execute;
- return \@{$sth->{NAME_lc}};
+ my $retval = \@{$sth->{NAME_lc}};
+ $sth->finish;
+
+ $retval;
}
# Returns arrayref of pk col names
$indices{$row->{INDEX_NAME}}->{$row->{ORDINAL_POSITION}} = $row->{COLUMN_NAME};
}
+ $sth->finish;
my @retval;
foreach my $index_name (keys %indices) {
$rels{$relid}->{tbl} = $uk_tbl;
$rels{$relid}->{cols}->{$uk_col} = $fk_col;
}
+ $sth->finish;
my @rels;
foreach my $relid (keys %rels) {
$result{$col_name} = \%column_info;
}
+ $sth->finish;
};
return \%result if !$@ && scalar keys %result;
}
See L<DBIx::Class::Schema::Loader::Base>.
+=head1 METHODS
+
+=head2 rescan
+
+SQLite will fail all further commands on a connection if the
+underlying schema has been modified. Therefore, any runtime
+changes requiring C<rescan> also require us to re-connect
+to the database. The C<rescan> method here handles that
+reconnection for you, but beware that this must occur for
+any other open sqlite connections as well.
+
=cut
+sub rescan {
+ my ($self, $schema) = @_;
+
+ $schema->storage->disconnect if $schema->storage;
+ $self->next::method($schema);
+}
+
# XXX this really needs a re-factor
sub _sqlite_parse_table {
my ($self, $table) = @_;
next unless lc( $row->{type} ) eq 'table';
push @tables, $row->{tbl_name};
}
+ $sth->finish;
return @tables;
}
my $obj15 = $rsobj15->find(1);
isa_ok( $obj15->loader_test14, $class14 );
}
+ }
- # rescan test
- SKIP: {
- skip 'SQLite does not like schema changes while connected', 4
- if $self->{vendor} =~ /sqlite/i;
-
- my @statements_rescan = (
- qq{
- CREATE TABLE loader_test25 (
- id INTEGER NOT NULL PRIMARY KEY,
- loader_test2 INTEGER NOT NULL,
- FOREIGN KEY (loader_test2) REFERENCES loader_test2 (id)
- ) $self->{innodb}
- },
- q{ INSERT INTO loader_test25 (id,loader_test2) VALUES(123, 1) },
- q{ INSERT INTO loader_test25 (id,loader_test2) VALUES(321, 2) },
- );
-
- my $dbh = $self->dbconnect(1);
- $dbh->do($_) for @statements_rescan;
- $dbh->disconnect;
-
- my @new = $conn->rescan;
- is(scalar(@new), 1);
- is($new[0], 'LoaderTest25');
-
- my $rsobj25 = $conn->resultset('LoaderTest25');
- isa_ok($rsobj25, 'DBIx::Class::ResultSet');
- my $obj25 = $rsobj25->find(123);
- isa_ok( $obj25->loader_test2, $class2);
- }
-
+ # rescan test
+ SKIP: {
+ skip $self->{skip_rels}, 4 if $self->{skip_rels};
+
+ my @statements_rescan = (
+ qq{
+ CREATE TABLE loader_test25 (
+ id INTEGER NOT NULL PRIMARY KEY,
+ loader_test2 INTEGER NOT NULL,
+ FOREIGN KEY (loader_test2) REFERENCES loader_test2 (id)
+ ) $self->{innodb}
+ },
+ q{ INSERT INTO loader_test25 (id,loader_test2) VALUES(123, 1) },
+ q{ INSERT INTO loader_test25 (id,loader_test2) VALUES(321, 2) },
+ );
+
+ my $dbh = $self->dbconnect(1);
+ $dbh->do($_) for @statements_rescan;
+ $dbh->disconnect;
+
+ my @new = $conn->rescan;
+ is(scalar(@new), 1);
+ is($new[0], 'LoaderTest25');
+
+ my $rsobj25 = $conn->resultset('LoaderTest25');
+ isa_ok($rsobj25, 'DBIx::Class::ResultSet');
+ my $obj25 = $rsobj25->find(123);
+ isa_ok( $obj25->loader_test2, $class2);
}
}
unless($self->{no_implicit_rels}) {
$dbh->do("DROP TABLE $_") for (@tables_implicit_rels);
}
- }
- unless($self->{vendor} =~ /sqlite/i) {
$dbh->do("DROP TABLE $_") for (@tables_rescan);
}
$dbh->do("DROP TABLE $_") for (@tables);