use DBIx::Class::Carp;
use Scalar::Util 'looks_like_number';
+use Try::Tiny;
use namespace::clean;
__PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::SQLite');
$self->_dbh->do("ROLLBACK TRANSACTION TO SAVEPOINT $name");
}
+sub _ping {
+ my $self = shift;
+ try { $self->_dbh->do('SELECT * FROM sqlite_master LIMIT 1'); 1 };
+}
+
sub deployment_statements {
my $self = shift;
my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_;
cmp_ok(@art_two, '==', 3, "Three artists returned");
### Now, disconnect the dbh, and move the db file;
-# create a new one and chmod 000 to prevent SQLite from connecting.
+# create a new one full of garbage, prevent SQLite from connecting.
$schema->storage->_dbh->disconnect;
move( $db_orig, $db_tmp )
or die "failed to move $db_orig to $db_tmp: $!";
-open DBFILE, '>', $db_orig;
-print DBFILE 'THIS IS NOT A REAL DATABASE';
-close DBFILE;
-chmod 0000, $db_orig;
+open my $db_file, '>', $db_orig;
+print $db_file 'THIS IS NOT A REAL DATABASE';
+close $db_file;
-### Try the operation again... it should fail, since there's no db
+### Try the operation again... it should fail, since there's no valid db
{
- # Catch the DBI connection error
- local $SIG{__WARN__} = sub {};
- dies_ok {
- my @art_three = $schema->resultset("Artist")->search( {}, { order_by => 'name DESC' } );
- } 'The operation failed';
+ # Catch the DBI connection error
+ local $SIG{__WARN__} = sub {};
+ throws_ok {
+ my @art_three = $schema->resultset("Artist")->search( {}, { order_by => 'name DESC' } );
+ } qr/not a database/, 'The operation failed';
}
-# otherwise can't unlink the fake db file
-$schema->storage->_dbh->disconnect if $^O eq 'MSWin32';
+ok (! $schema->storage->connected, 'We are not connected' );
### Now, move the db file back to the correct name
unlink($db_orig) or die "could not delete $db_orig: $!";