1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
11 use DBIx::Class::_Util 'dump_value';
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 $storage->isa('DBIx::Class::Storage::DBI::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;
59 # testing various invocations of connect_info ([ ... ])
61 my $coderef = sub { 42 };
63 'connect_info ([ $d, $u, $p, \%attr, \%extra_attr])' => {
69 on_connect_do => [qw/a b c/],
74 on_disconnect_do => [qw/d e f/],
86 %{$storage->_default_dbi_connect_attributes || {} },
93 'connect_info ([ \%code, \%extra_attr ])' => {
97 on_connect_do => [qw/a b c/],
100 on_disconnect_do => [qw/d e f/],
107 dbi_connect_info => [
112 'connect_info ([ \%attr ])' => {
115 on_connect_do => [qw/a b c/],
118 on_disconnect_do => [qw/d e f/],
127 dbi_connect_info => [
132 %{$storage->_default_dbi_connect_attributes || {} },
137 warn => qr/\QYou provided explicit AutoCommit => 0 in your connection_info/,
139 'connect_info ([ \%attr_with_coderef ])' => {
141 dbh_maker => $coderef,
144 on_connect_do => [qw/a b c/],
145 on_disconnect_do => [qw/d e f/],
147 dbi_connect_info => [
150 warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
154 for my $type (keys %$invocations) {
155 local $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK};
157 # we can not use a cloner portably because of the coderef
158 # so compare dumps instead
159 my $arg_dump = dump_value $invocations->{$type}{args};
162 sub { $storage->connect_info ($invocations->{$type}{args}) },
163 $invocations->{$type}{warn} || [],
164 'Warned about ignored attributes',
169 dump_value $invocations->{$type}{args},
170 "$type didn't modify passed arguments",
173 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
174 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
177 [$storage->on_connect_do, $storage->on_disconnect_do ],
178 [ [qw/a b c/], [qw/d e f/] ],
179 "$type correctly parsed DBIC specific on_[dis]connect_do",
183 # make sure connection-less storages do not throw on _determine_driver
184 # but work with ENV at the same time
185 SKIP: for my $env_dsn (undef, (DBICTest->_database)[0] ) {
187 skip 'This set of tests relies on being connected to SQLite', 1
188 if $env_dsn and $env_dsn !~ /\:SQLite\:/;
190 local $ENV{DBI_DSN} = $env_dsn || '';
192 my $s = DBICTest::Schema->connect();
194 $s->storage->connect_info,
196 'Starting with no explicitly passed in connect info'
197 . ($env_dsn ? ' (with DBI_DSN)' : ''),
200 my $sm = $s->storage->sql_maker;
202 ok (! $s->storage->connected, 'Storage does not appear connected after SQLMaker instance is taken');
205 isa_ok($sm, 'DBIx::Class::SQLMaker');
207 ok ( $s->storage->_driver_determined, 'Driver determined (with DBI_DSN)');
208 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );
211 isa_ok($sm, 'DBIx::Class::SQLMaker');
213 ok (! $s->storage->_driver_determined, 'Driver undetermined');
216 $s->storage->ensure_connected
217 } qr/You did not provide any connection_info/,
218 'sensible exception on empty conninfo connect';