11 my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
13 is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
14 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );
16 my $storage = $schema->storage;
17 $storage->ensure_connected;
20 $schema->storage->throw_exception('test_exception_42');
21 } qr/\btest_exception_42\b/, 'basic exception';
24 $schema->resultset('CD')->search_literal('broken +%$#$1')->all;
25 } qr/prepare_cached failed/, 'exception via DBI->HandleError, etc';
28 # testing various invocations of connect_info ([ ... ])
30 my $coderef = sub { 42 };
32 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
38 on_connect_do => [qw/a b c/],
43 on_disconnect_do => [qw/d e f/],
55 %{$storage->_default_dbi_connect_attributes || {} },
62 'connect_info ([ \%code, \%extra_attr ])' => {
66 on_connect_do => [qw/a b c/],
69 on_disconnect_do => [qw/d e f/],
81 'connect_info ([ \%attr ])' => {
84 on_connect_do => [qw/a b c/],
87 on_disconnect_do => [qw/d e f/],
101 %{$storage->_default_dbi_connect_attributes || {} },
106 warn => qr/\QYou provided explicit AutoCommit => 0 in your connection_info/,
108 'connect_info ([ \%attr_with_coderef ])' => {
110 dbh_maker => $coderef,
113 on_connect_do => [qw/a b c/],
114 on_disconnect_do => [qw/d e f/],
116 dbi_connect_info => [
119 warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
123 for my $type (keys %$invocations) {
124 local $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK};
126 # we can not use a cloner portably because of the coderef
127 # so compare dumps instead
128 local $Data::Dumper::Sortkeys = 1;
129 my $arg_dump = Dumper ($invocations->{$type}{args});
132 sub { $storage->connect_info ($invocations->{$type}{args}) },
133 $invocations->{$type}{warn} || [],
134 'Warned about ignored attributes',
137 is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
139 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
140 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
143 [$storage->on_connect_do, $storage->on_disconnect_do ],
144 [ [qw/a b c/], [qw/d e f/] ],
145 "$type correctly parsed DBIC specific on_[dis]connect_do",
149 # make sure connection-less storages do not throw on _determine_driver
152 local $ENV{DBI_DRIVER};
154 my $s = DBICTest::Schema->connect;
156 $s->storage->connect_info,
158 'Starting with no connection info',
162 $s->storage->sql_maker,
163 'DBIx::Class::SQLMaker',
164 'Getting back an SQLMaker succesfully',
167 ok (! $s->storage->_driver_determined, 'Driver undetermined');
169 ok (! $s->storage->connected, 'Storage does not appear connected');
172 $s->storage->ensure_connected
173 } qr/You did not provide any connection_info/,
174 'sensible exception on empty conninfo connect'