12 package DBICTest::ExplodingStorage::Sth;
16 sub execute { die "Kablammo!" }
20 package DBICTest::ExplodingStorage;
23 use base 'DBIx::Class::Storage::DBI::SQLite';
27 my ($self, $sql) = @_;
28 return bless {}, "DBICTest::ExplodingStorage::Sth" unless $count++;
29 return $self->next::method($sql);
33 return 0 if $count == 1;
34 return shift->next::method(@_);
38 my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
40 is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
41 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );
43 my $storage = $schema->storage;
44 $storage->ensure_connected;
47 $schema->storage->throw_exception('test_exception_42');
48 } qr/\btest_exception_42\b/, 'basic exception';
51 $schema->resultset('CD')->search_literal('broken +%$#$1')->all;
52 } qr/prepare_cached failed/, 'exception via DBI->HandleError, etc';
54 bless $storage, "DBICTest::ExplodingStorage";
55 $schema->storage($storage);
58 $schema->resultset('Artist')->create({ name => "Exploding Sheep" });
59 } 'Exploding $sth->execute was caught';
61 is(1, $schema->resultset('Artist')->search({name => "Exploding Sheep" })->count,
62 "And the STH was retired");
65 # testing various invocations of connect_info ([ ... ])
67 my $coderef = sub { 42 };
69 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
75 on_connect_do => [qw/a b c/],
80 on_disconnect_do => [qw/d e f/],
92 %{$storage->_default_dbi_connect_attributes || {} },
99 'connect_info ([ \%code, \%extra_attr ])' => {
103 on_connect_do => [qw/a b c/],
106 on_disconnect_do => [qw/d e f/],
113 dbi_connect_info => [
118 'connect_info ([ \%attr ])' => {
121 on_connect_do => [qw/a b c/],
124 on_disconnect_do => [qw/d e f/],
133 dbi_connect_info => [
138 %{$storage->_default_dbi_connect_attributes || {} },
143 warn => qr/\QYou provided explicit AutoCommit => 0 in your connection_info/,
145 'connect_info ([ \%attr_with_coderef ])' => {
147 dbh_maker => $coderef,
150 on_connect_do => [qw/a b c/],
151 on_disconnect_do => [qw/d e f/],
153 dbi_connect_info => [
156 warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
160 for my $type (keys %$invocations) {
162 # we can not use a cloner portably because of the coderef
163 # so compare dumps instead
164 local $Data::Dumper::Sortkeys = 1;
165 my $arg_dump = Dumper ($invocations->{$type}{args});
168 sub { $storage->connect_info ($invocations->{$type}{args}) },
169 $invocations->{$type}{warn} || (),
170 'Warned about ignored attributes',
173 is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
175 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
176 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
179 [$storage->on_connect_do, $storage->on_disconnect_do ],
180 [ [qw/a b c/], [qw/d e f/] ],
181 "$type correctly parsed DBIC specific on_[dis]connect_do",