11 package DBICTest::ExplodingStorage::Sth;
15 sub execute { die "Kablammo!" }
19 package DBICTest::ExplodingStorage;
22 use base 'DBIx::Class::Storage::DBI::SQLite';
26 my ($self, $sql) = @_;
27 return bless {}, "DBICTest::ExplodingStorage::Sth" unless $count++;
28 return $self->next::method($sql);
32 return 0 if $count == 1;
33 return shift->next::method(@_);
37 my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
39 is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
40 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );
42 my $storage = $schema->storage;
43 $storage->ensure_connected;
46 $schema->storage->throw_exception('test_exception_42');
48 like($@, qr/\btest_exception_42\b/, 'basic exception');
51 $schema->resultset('CD')->search_literal('broken +%$#$1')->all;
53 like($@, qr/prepare_cached failed/, 'exception via DBI->HandleError, etc');
55 bless $storage, "DBICTest::ExplodingStorage";
56 $schema->storage($storage);
59 $schema->resultset('Artist')->create({ name => "Exploding Sheep" });
62 is($@, "", "Exploding \$sth->execute was caught");
64 is(1, $schema->resultset('Artist')->search({name => "Exploding Sheep" })->count,
65 "And the STH was retired");
68 # testing various invocations of connect_info ([ ... ])
70 my $coderef = sub { 42 };
72 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
78 on_connect_do => [qw/a b c/],
83 on_disconnect_do => [qw/d e f/],
95 %{$storage->_default_dbi_connect_attributes || {} },
102 'connect_info ([ \%code, \%extra_attr ])' => {
106 on_connect_do => [qw/a b c/],
109 on_disconnect_do => [qw/d e f/],
116 dbi_connect_info => [
121 'connect_info ([ \%attr ])' => {
124 on_connect_do => [qw/a b c/],
127 on_disconnect_do => [qw/d e f/],
136 dbi_connect_info => [
141 %{$storage->_default_dbi_connect_attributes || {} },
147 'connect_info ([ \%attr_with_coderef ])' => {
149 dbh_maker => $coderef,
152 on_connect_do => [qw/a b c/],
153 on_disconnect_do => [qw/d e f/],
155 dbi_connect_info => [
158 warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
162 for my $type (keys %$invocations) {
164 # we can not use a cloner portably because of the coderef
165 # so compare dumps instead
166 local $Data::Dumper::Sortkeys = 1;
167 my $arg_dump = Dumper ($invocations->{$type}{args});
172 sub { $storage->connect_info ($invocations->{$type}{args}) },
173 $invocations->{$type}{warn} || (),
174 'Warned about ignored attributes',
177 is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
179 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
180 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
183 [$storage->on_connect_do, $storage->on_disconnect_do ],
184 [ [qw/a b c/], [qw/d e f/] ],
185 "$type correctly parsed DBIC specific on_[dis]connect_do",