1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
13 my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
15 my $storage = $schema->storage;
19 'DBIx::Class::Storage::DBI::SQLite',
20 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite'
21 ) unless $ENV{DBICTEST_VIA_REPLICATED};
24 $schema->storage->throw_exception('test_exception_42');
25 } qr/\btest_exception_42\b/, 'basic exception';
28 $schema->resultset('CD')->search_literal('broken +%$#$1')->all;
29 } qr/prepare_cached failed/, 'exception via DBI->HandleError, etc';
32 # make sure repeated disconnection works
34 my $fn = DBICTest->_sqlite_dbfilename;
37 $schema->storage->ensure_connected;
38 my $dbh = $schema->storage->dbh;
39 $schema->storage->disconnect for 1,2;
45 $schema->storage->ensure_connected;
46 $schema->storage->disconnect for 1,2;
48 $schema->storage->disconnect for 1,2;
52 $schema->storage->ensure_connected;
53 $schema->storage->_dbh->disconnect;
55 $schema->storage->disconnect for 1,2;
60 # testing various invocations of connect_info ([ ... ])
62 my $coderef = sub { 42 };
64 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
70 on_connect_do => [qw/a b c/],
75 on_disconnect_do => [qw/d e f/],
87 %{$storage->_default_dbi_connect_attributes || {} },
94 'connect_info ([ \%code, \%extra_attr ])' => {
98 on_connect_do => [qw/a b c/],
101 on_disconnect_do => [qw/d e f/],
108 dbi_connect_info => [
113 'connect_info ([ \%attr ])' => {
116 on_connect_do => [qw/a b c/],
119 on_disconnect_do => [qw/d e f/],
128 dbi_connect_info => [
133 %{$storage->_default_dbi_connect_attributes || {} },
138 warn => qr/\QYou provided explicit AutoCommit => 0 in your connection_info/,
140 'connect_info ([ \%attr_with_coderef ])' => {
142 dbh_maker => $coderef,
145 on_connect_do => [qw/a b c/],
146 on_disconnect_do => [qw/d e f/],
148 dbi_connect_info => [
151 warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
155 for my $type (keys %$invocations) {
156 local $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK};
158 # we can not use a cloner portably because of the coderef
159 # so compare dumps instead
160 local $Data::Dumper::Sortkeys = 1;
161 my $arg_dump = Dumper ($invocations->{$type}{args});
164 sub { $storage->connect_info ($invocations->{$type}{args}) },
165 $invocations->{$type}{warn} || [],
166 'Warned about ignored attributes',
169 is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
171 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
172 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
175 [$storage->on_connect_do, $storage->on_disconnect_do ],
176 [ [qw/a b c/], [qw/d e f/] ],
177 "$type correctly parsed DBIC specific on_[dis]connect_do",
181 # make sure connection-less storages do not throw on _determine_driver
182 # but work with ENV at the same time
183 SKIP: for my $env_dsn (undef, (DBICTest->_database)[0] ) {
184 skip 'Subtest relies on being connected to SQLite', 1
185 if $env_dsn and $env_dsn !~ /\:SQLite\:/;
187 local $ENV{DBI_DSN} = $env_dsn || '';
189 my $s = DBICTest::Schema->connect();
191 $s->storage->connect_info,
193 'Starting with no explicitly passed in connect info'
194 . ($env_dsn ? ' (with DBI_DSN)' : ''),
197 my $sm = $s->storage->sql_maker;
199 ok (! $s->storage->connected, 'Storage does not appear connected after SQLMaker instance is taken');
202 isa_ok($sm, 'DBIx::Class::SQLMaker');
204 ok ( $s->storage->_driver_determined, 'Driver determined (with DBI_DSN)');
205 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );
208 isa_ok($sm, 'DBIx::Class::SQLMaker');
210 ok (! $s->storage->_driver_determined, 'Driver undetermined');
213 $s->storage->ensure_connected
214 } qr/You did not provide any connection_info/,
215 'sensible exception on empty conninfo connect';