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 # testing various invocations of connect_info ([ ... ])
32 my $coderef = sub { 42 };
34 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
40 on_connect_do => [qw/a b c/],
45 on_disconnect_do => [qw/d e f/],
57 %{$storage->_default_dbi_connect_attributes || {} },
64 'connect_info ([ \%code, \%extra_attr ])' => {
68 on_connect_do => [qw/a b c/],
71 on_disconnect_do => [qw/d e f/],
83 'connect_info ([ \%attr ])' => {
86 on_connect_do => [qw/a b c/],
89 on_disconnect_do => [qw/d e f/],
103 %{$storage->_default_dbi_connect_attributes || {} },
108 warn => qr/\QYou provided explicit AutoCommit => 0 in your connection_info/,
110 'connect_info ([ \%attr_with_coderef ])' => {
112 dbh_maker => $coderef,
115 on_connect_do => [qw/a b c/],
116 on_disconnect_do => [qw/d e f/],
118 dbi_connect_info => [
121 warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
125 for my $type (keys %$invocations) {
126 local $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK};
128 # we can not use a cloner portably because of the coderef
129 # so compare dumps instead
130 local $Data::Dumper::Sortkeys = 1;
131 my $arg_dump = Dumper ($invocations->{$type}{args});
134 sub { $storage->connect_info ($invocations->{$type}{args}) },
135 $invocations->{$type}{warn} || [],
136 'Warned about ignored attributes',
139 is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
141 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
142 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
145 [$storage->on_connect_do, $storage->on_disconnect_do ],
146 [ [qw/a b c/], [qw/d e f/] ],
147 "$type correctly parsed DBIC specific on_[dis]connect_do",
151 $schema->storage->_dbh->disconnect;
153 # make sure connection-less storages do not throw on _determine_driver
154 # but work with ENV at the same time
155 SKIP: for my $env_dsn (undef, (DBICTest->_database)[0] ) {
156 skip 'Subtest relies on being connected to SQLite', 1
157 if $env_dsn and $env_dsn !~ /\:SQLite\:/;
159 local $ENV{DBI_DSN} = $env_dsn || '';
161 my $s = DBICTest::Schema->connect();
163 $s->storage->connect_info,
165 'Starting with no explicitly passed in connect info'
166 . ($env_dsn ? ' (with DBI_DSN)' : ''),
169 my $sm = $s->storage->sql_maker;
171 ok (! $s->storage->connected, 'Storage does not appear connected after SQLMaker instance is taken');
174 isa_ok($sm, 'DBIx::Class::SQLMaker');
176 ok ( $s->storage->_driver_determined, 'Driver determined (with DBI_DSN)');
177 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );
180 isa_ok($sm, 'DBIx::Class::SQLMaker');
182 ok (! $s->storage->_driver_determined, 'Driver undetermined');
185 $s->storage->ensure_connected
186 } qr/You did not provide any connection_info/,
187 'sensible exception on empty conninfo connect';