11 my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
13 my $storage = $schema->storage;
17 'DBIx::Class::Storage::DBI::SQLite',
18 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite'
19 ) unless $ENV{DBICTEST_VIA_REPLICATED};
22 $schema->storage->throw_exception('test_exception_42');
23 } qr/\btest_exception_42\b/, 'basic exception';
26 $schema->resultset('CD')->search_literal('broken +%$#$1')->all;
27 } qr/prepare_cached failed/, 'exception via DBI->HandleError, etc';
30 # make sure repeated disconnection works
32 my $fn = DBICTest->_sqlite_dbfilename;
35 $schema->storage->ensure_connected;
36 my $dbh = $schema->storage->dbh;
37 $schema->storage->disconnect for 1,2;
43 $schema->storage->ensure_connected;
44 $schema->storage->disconnect for 1,2;
46 $schema->storage->disconnect for 1,2;
50 $schema->storage->ensure_connected;
51 $schema->storage->_dbh->disconnect;
53 $schema->storage->disconnect for 1,2;
58 # testing various invocations of connect_info ([ ... ])
60 my $coderef = sub { 42 };
62 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
68 on_connect_do => [qw/a b c/],
73 on_disconnect_do => [qw/d e f/],
85 %{$storage->_default_dbi_connect_attributes || {} },
92 'connect_info ([ \%code, \%extra_attr ])' => {
96 on_connect_do => [qw/a b c/],
99 on_disconnect_do => [qw/d e f/],
106 dbi_connect_info => [
111 'connect_info ([ \%attr ])' => {
114 on_connect_do => [qw/a b c/],
117 on_disconnect_do => [qw/d e f/],
126 dbi_connect_info => [
131 %{$storage->_default_dbi_connect_attributes || {} },
136 warn => qr/\QYou provided explicit AutoCommit => 0 in your connection_info/,
138 'connect_info ([ \%attr_with_coderef ])' => {
140 dbh_maker => $coderef,
143 on_connect_do => [qw/a b c/],
144 on_disconnect_do => [qw/d e f/],
146 dbi_connect_info => [
149 warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
153 for my $type (keys %$invocations) {
154 local $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK};
156 # we can not use a cloner portably because of the coderef
157 # so compare dumps instead
158 local $Data::Dumper::Sortkeys = 1;
159 my $arg_dump = Dumper ($invocations->{$type}{args});
162 sub { $storage->connect_info ($invocations->{$type}{args}) },
163 $invocations->{$type}{warn} || [],
164 'Warned about ignored attributes',
167 is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
169 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
170 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
173 [$storage->on_connect_do, $storage->on_disconnect_do ],
174 [ [qw/a b c/], [qw/d e f/] ],
175 "$type correctly parsed DBIC specific on_[dis]connect_do",
179 # make sure connection-less storages do not throw on _determine_driver
180 # but work with ENV at the same time
181 SKIP: for my $env_dsn (undef, (DBICTest->_database)[0] ) {
182 skip 'Subtest relies on being connected to SQLite', 1
183 if $env_dsn and $env_dsn !~ /\:SQLite\:/;
185 local $ENV{DBI_DSN} = $env_dsn || '';
187 my $s = DBICTest::Schema->connect();
189 $s->storage->connect_info,
191 'Starting with no explicitly passed in connect info'
192 . ($env_dsn ? ' (with DBI_DSN)' : ''),
195 my $sm = $s->storage->sql_maker;
197 ok (! $s->storage->connected, 'Storage does not appear connected after SQLMaker instance is taken');
200 isa_ok($sm, 'DBIx::Class::SQLMaker');
202 ok ( $s->storage->_driver_determined, 'Driver determined (with DBI_DSN)');
203 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );
206 isa_ok($sm, 'DBIx::Class::SQLMaker');
208 ok (! $s->storage->_driver_determined, 'Driver undetermined');
211 $s->storage->ensure_connected
212 } qr/You did not provide any connection_info/,
213 'sensible exception on empty conninfo connect';