[Bast-commits] r3172 - in branches/DBIx-Class-Schema-Loader/current: lib/DBIx/Class/Schema/Loader lib/DBIx/Class/Schema/Loader/DBI t/lib

blblack at dev.catalyst.perl.org blblack at dev.catalyst.perl.org
Sat Mar 31 07:54:51 GMT 2007


Author: blblack
Date: 2007-03-31 07:54:51 +0100 (Sat, 31 Mar 2007)
New Revision: 3172

Modified:
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm
   branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
Log:
sqlite fixups

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm	2007-03-31 01:07:15 UTC (rev 3171)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm	2007-03-31 06:54:51 UTC (rev 3172)
@@ -26,8 +26,26 @@
 
 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) = @_;
@@ -151,6 +169,7 @@
         next unless lc( $row->{type} ) eq 'table';
         push @tables, $row->{tbl_name};
     }
+    $sth->finish;
     return @tables;
 }
 

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm	2007-03-31 01:07:15 UTC (rev 3171)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm	2007-03-31 06:54:51 UTC (rev 3172)
@@ -109,7 +109,10 @@
 
     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 @@
 
         $indices{$row->{INDEX_NAME}}->{$row->{ORDINAL_POSITION}} = $row->{COLUMN_NAME};
     }
+    $sth->finish;
 
     my @retval;
     foreach my $index_name (keys %indices) {
@@ -184,6 +188,7 @@
         $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 @@
 
                 $result{$col_name} = \%column_info;
             }
+            $sth->finish;
         };
       return \%result if !$@ && scalar keys %result;
     }

Modified: branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm	2007-03-31 01:07:15 UTC (rev 3171)
+++ branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm	2007-03-31 06:54:51 UTC (rev 3172)
@@ -444,38 +444,36 @@
             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;
+    # 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 @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 $dbh = $self->dbconnect(1);
+        $dbh->do($_) for @statements_rescan;
+        $dbh->disconnect;
 
-            my @new = $conn->rescan;
-            is(scalar(@new), 1);
-            is($new[0], 'LoaderTest25');
+        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);
-        }
-
+        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 @@
         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);




More information about the Bast-commits mailing list