12 require inc::Module::Install;
13 plan $Module::Install::AUTHOR
15 : (skip_all => 'Test temporarily disabled due to a widespread buggy SQLite version')
19 my $db_orig = "$FindBin::Bin/var/DBIxClass.db";
20 my $db_tmp = "$db_orig.tmp";
22 # Set up the "usual" sqlite for DBICTest
23 my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
25 # Make sure we're connected by doing something
26 my @art = $schema->resultset("Artist")->search({ }, { order_by => 'name DESC'});
27 cmp_ok(@art, '==', 3, "Three artists returned");
29 # Disconnect the dbh, and be sneaky about it
30 # Also test if DBD::SQLite finaly knows how to ->disconnect properly
32 local $TODO = 'SQLite is evil/braindead. Once this test starts passing, remove the related atrocity from DBIx::Class::Storage::DBI::SQLite';
34 local $SIG{__WARN__} = sub { $w = shift };
35 $schema->storage->_dbh->disconnect;
36 ok ($w !~ /active statement handles/, 'SQLite can disconnect properly \o/');
39 # Try the operation again - What should happen here is:
40 # 1. S::DBI blindly attempts the SELECT, which throws an exception
41 # 2. It catches the exception, checks ->{Active}/->ping, sees the disconnected state...
42 # 3. Reconnects, and retries the operation
44 my @art_two = $schema->resultset("Artist")->search({ }, { order_by => 'name DESC'});
45 cmp_ok(@art_two, '==', 3, "Three artists returned");
47 ### Now, disconnect the dbh, and move the db file;
48 # create a new one and chmod 000 to prevent SQLite from connecting.
49 $schema->storage->_dbh->disconnect;
50 move( $db_orig, $db_tmp );
51 open DBFILE, '>', $db_orig;
52 print DBFILE 'THIS IS NOT A REAL DATABASE';
56 ### Try the operation again... it should fail, since there's no db
58 # Catch the DBI connection error
59 local $SIG{__WARN__} = sub {};
61 my @art_three = $schema->resultset("Artist")->search( {}, { order_by => 'name DESC' } );
63 ok( $@, 'The operation failed' );
66 ### Now, move the db file back to the correct name
68 move( $db_tmp, $db_orig );
71 skip "Cannot reconnect if original connection didn't fail", 2
72 if ( $@ =~ /encrypted or is not a database/ );
74 ### Try the operation again... this time, it should succeed
77 @art_four = $schema->resultset("Artist")->search( {}, { order_by => 'name DESC' } );
79 ok( !$@, 'The operation succeeded' );
80 cmp_ok( @art_four, '==', 3, "Three artists returned" );