4 use Test::More tests => 12;
10 my $schema = DBICTest->init_schema(
15 ok $schema->connection(
18 on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)',
23 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
25 'string version on_connect_do() worked'
28 $schema->storage->disconnect;
30 ok $schema->connection(
34 'CREATE TABLE TEST_empty (id INTEGER)',
35 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
39 [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
44 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
45 [ [ 2 ], [ 3 ], [ 7 ] ],
46 'on_connect_do() worked'
48 eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
49 ok $@, 'Searching for nonexistent table dies';
51 $schema->storage->disconnect();
53 my($connected, $disconnected, @cb_args);
54 ok $schema->connection(
57 on_connect_do => sub { $connected = 1; @cb_args = @_; },
58 on_disconnect_do => sub { $disconnected = 1 },
60 ), 'second connection()';
61 $schema->storage->dbh->do('SELECT 1');
62 ok $connected, 'on_connect_do() called after connect()';
63 ok ! $disconnected, 'on_disconnect_do() not called after connect()';
64 $schema->storage->disconnect();
65 ok $disconnected, 'on_disconnect_do() called after disconnect()';
67 isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook');
71 ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
77 eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
78 ok $@, 'Reading from dropped table fails';
82 sub insert_from_subref {
85 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
86 'INSERT INTO TEST_empty VALUES (7)',