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
150 # but work with ENV at the same time
151 SKIP: for my $env_dsn (undef, (DBICTest->_database)[0] ) {
152 skip 'Subtest relies on being connected to SQLite', 1
153 if $env_dsn and $env_dsn !~ /\:SQLite\:/;
155 local $ENV{DBI_DSN} = $env_dsn || '';
157 my $s = DBICTest::Schema->connect();
159 $s->storage->connect_info,
161 'Starting with no explicitly passed in connect info'
162 . ($env_dsn ? ' (with DBI_DSN)' : ''),
165 my $sm = $s->storage->sql_maker;
167 ok (! $s->storage->connected, 'Storage does not appear connected after SQLMaker instance is taken');
170 isa_ok($sm, 'DBIx::Class::SQLMaker');
172 ok ( $s->storage->_driver_determined, 'Driver determined (with DBI_DSN)');
173 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );
176 isa_ok($sm, 'DBIx::Class::SQLMaker');
178 ok (! $s->storage->_driver_determined, 'Driver undetermined');
181 $s->storage->ensure_connected
182 } qr/You did not provide any connection_info/,
183 'sensible exception on empty conninfo connect';