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