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 $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 my $arg_dump = dump_value $invocations->{$type}{args};
163 sub { $storage->connect_info ($invocations->{$type}{args}) },
164 $invocations->{$type}{warn} || [],
165 'Warned about ignored attributes',
170 dump_value $invocations->{$type}{args},
171 "$type didn't modify passed arguments",
174 is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
175 ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
178 [$storage->on_connect_do, $storage->on_disconnect_do ],
179 [ [qw/a b c/], [qw/d e f/] ],
180 "$type correctly parsed DBIC specific on_[dis]connect_do",
184 # make sure connection-less storages do not throw on _determine_driver
185 # but work with ENV at the same time
186 SKIP: for my $env_dsn (undef, (DBICTest->_database)[0] ) {
188 skip 'This set of tests relies on being connected to SQLite', 1
189 if $env_dsn and $env_dsn !~ /\:SQLite\:/;
191 local $ENV{DBI_DSN} = $env_dsn || '';
193 my $s = DBICTest::Schema->connect();
195 $s->storage->connect_info,
197 'Starting with no explicitly passed in connect info'
198 . ($env_dsn ? ' (with DBI_DSN)' : ''),
201 my $sm = $s->storage->sql_maker;
203 ok (! $s->storage->connected, 'Storage does not appear connected after SQLMaker instance is taken');
206 isa_ok($sm, 'DBIx::Class::SQLMaker');
208 ok ( $s->storage->_driver_determined, 'Driver determined (with DBI_DSN)');
209 isa_ok ( $s->storage, 'DBIx::Class::Storage::DBI::SQLite' );
212 isa_ok($sm, 'DBIx::Class::SQLMaker');
214 ok (! $s->storage->_driver_determined, 'Driver undetermined');
217 $s->storage->ensure_connected
218 } qr/You did not provide any connection_info/,
219 'sensible exception on empty conninfo connect';