From: Brandon Black Date: Sat, 31 Mar 2007 06:54:51 +0000 (+0000) Subject: sqlite fixups X-Git-Tag: 0.03999_01~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b7f80f94f4cbcd0976dfa0c86f478e3b25e7107;p=dbsrgits%2FDBIx-Class-Schema-Loader.git sqlite fixups --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index f21489a..39d5942 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -109,7 +109,10 @@ sub _table_columns { 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 @@ -147,6 +150,7 @@ sub _table_uniq_info { $indices{$row->{INDEX_NAME}}->{$row->{ORDINAL_POSITION}} = $row->{COLUMN_NAME}; } + $sth->finish; my @retval; foreach my $index_name (keys %indices) { @@ -184,6 +188,7 @@ sub _table_fk_info { $rels{$relid}->{tbl} = $uk_tbl; $rels{$relid}->{cols}->{$uk_col} = $fk_col; } + $sth->finish; my @rels; foreach my $relid (keys %rels) { @@ -219,6 +224,7 @@ sub _columns_info_for { $result{$col_name} = \%column_info; } + $sth->finish; }; return \%result if !$@ && scalar keys %result; } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index 2bba30f..581c2d5 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -26,8 +26,26 @@ DBIx::Class::Schema::Loader::DBI::SQLite - DBIx::Class::Schema::Loader::DBI SQLi See L. +=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 also require us to re-connect +to the database. The C 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) = @_; @@ -151,6 +169,7 @@ sub _tables_list { next unless lc( $row->{type} ) eq 'table'; push @tables, $row->{tbl_name}; } + $sth->finish; return @tables; } diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 2e4143c..2bad164 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -444,38 +444,36 @@ sub run_tests { 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); } } @@ -876,8 +874,6 @@ sub drop_tables { 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);