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 # make sure repeated disconnection works
30 my $fn = DBICTest->_sqlite_dbfilename;
33 $schema->storage->ensure_connected;
34 my $dbh = $schema->storage->dbh;
35 $schema->storage->disconnect for 1,2;
41 $schema->storage->ensure_connected;
42 $schema->storage->disconnect for 1,2;
44 $schema->storage->disconnect for 1,2;
48 $schema->storage->ensure_connected;
49 $schema->storage->_dbh->disconnect;
51 $schema->storage->disconnect for 1,2;
56 # testing various invocations of connect_info ([ ... ])
58 my $coderef = sub { 42 };
60 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
66 on_connect_do => [qw/a b c/],
71 on_disconnect_do => [qw/d e f/],
83 %{$storage->_default_dbi_connect_attributes || {} },
90 'connect_info ([ \%code, \%extra_attr ])' => {
94 on_connect_do => [qw/a b c/],
97 on_disconnect_do => [qw/d e f/],
104 dbi_connect_info => [
109 'connect_info ([ \%attr ])' => {
112 on_connect_do => [qw/a b c/],
115 on_disconnect_do => [qw/d e f/],
124 dbi_connect_info => [
129 %{$storage->_default_dbi_connect_attributes || {} },
134 warn => qr/\QYou provided explicit AutoCommit => 0 in your connection_info/,
136 'connect_info ([ \%attr_with_coderef ])' => {
138 dbh_maker => $coderef,
141 on_connect_do => [qw/a b c/],
142 on_disconnect_do => [qw/d e f/],
144 dbi_connect_info => [
147 warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
151 for my $type (keys %$invocations) {
152 local $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK};
154 # we can not use a cloner portably because of the coderef
155 # so compare dumps instead
156 local $Data::Dumper::Sortkeys = 1;
157 my $arg_dump = Dumper ($invocations->{$type}{args});
160 sub { $storage->connect_info ($invocations->{$type}{args}) },
161 $invocations->{$type}{warn} || [],
162 'Warned about ignored attributes',
165 is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
167 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
168 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
171 [$storage->on_connect_do, $storage->on_disconnect_do ],
172 [ [qw/a b c/], [qw/d e f/] ],
173 "$type correctly parsed DBIC specific on_[dis]connect_do",
177 # make sure connection-less storages do not throw on _determine_driver
178 # but work with ENV at the same time
179 SKIP: for my $env_dsn (undef, (DBICTest->_database)[0] ) {
180 skip 'Subtest relies on being connected to SQLite', 1
181 if $env_dsn and $env_dsn !~ /\:SQLite\:/;
183 local $ENV{DBI_DSN} = $env_dsn || '';
185 my $s = DBICTest::Schema->connect();
187 $s->storage->connect_info,
189 'Starting with no explicitly passed in connect info'
190 . ($env_dsn ? ' (with DBI_DSN)' : ''),
193 my $sm = $s->storage->sql_maker;
195 ok (! $s->storage->connected, 'Storage does not appear connected after SQLMaker instance is taken');
198 isa_ok($sm, 'DBIx::Class::SQLMaker');
200 ok ( $s->storage->_driver_determined, 'Driver determined (with DBI_DSN)');
201 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );
204 isa_ok($sm, 'DBIx::Class::SQLMaker');
206 ok (! $s->storage->_driver_determined, 'Driver undetermined');
209 $s->storage->ensure_connected
210 } qr/You did not provide any connection_info/,
211 'sensible exception on empty conninfo connect';