4 BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }
6 # !!! do not replace this with done_testing - tests reside in the callbacks
7 # !!! number of calls is important
8 use Test::More tests => 13;
18 my $schema = DBICTest->init_schema(
23 ok $schema->connection(
26 on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)',
31 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
33 'string version on_connect_do() worked'
36 $schema->storage->disconnect;
38 ok $schema->connection(
39 sub { DBI->connect(DBICTest->_database, undef, undef, { AutoCommit => 0 }) },
41 # DO NOT REMOVE - this seems like an unrelated piece of info,
42 # but is in fact a test for a bug where setting an accessor-via-option
43 # would trigger an early connect *bypassing* the on_connect_* pieces
44 cursor_class => 'DBIx::Class::Storage::Cursor',
47 'CREATE TABLE TEST_empty (id INTEGER)',
48 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
52 [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
57 $schema->storage->ensure_connected
58 } qr/The 'RaiseError' of the externally supplied DBI handle is set to false/,
59 'Warning on clobbered AutoCommit => 0 fired';
62 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
63 [ [ 2 ], [ 3 ], [ 7 ] ],
64 'on_connect_do() worked'
67 $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent');
68 } 'Searching for nonexistent table dies';
70 $schema->storage->disconnect();
72 my($connected, $disconnected, @cb_args);
73 ok $schema->connection(
76 on_connect_do => sub { $connected = 1; @cb_args = @_; },
77 on_disconnect_do => sub { $disconnected = 1 },
79 ), 'second connection()';
80 $schema->storage->dbh->do('SELECT 1');
81 ok $connected, 'on_connect_do() called after connect()';
82 ok ! $disconnected, 'on_disconnect_do() not called after connect()';
83 $schema->storage->disconnect();
84 ok $disconnected, 'on_disconnect_do() called after disconnect()';
86 isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook');
91 ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
99 $storage->dbh->do('SELECT 1 FROM TEST_empty');
100 } 'Reading from dropped table fails';
104 sub insert_from_subref {
107 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
108 'INSERT INTO TEST_empty VALUES (7)',