4 use Test::More tests => 12;
11 my $schema = DBICTest->init_schema(
16 ok $schema->connection(
19 on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)',
24 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
26 'string version on_connect_do() worked'
29 $schema->storage->disconnect;
31 ok $schema->connection(
32 sub { DBI->connect(DBICTest->_database) },
35 'CREATE TABLE TEST_empty (id INTEGER)',
36 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
40 [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
45 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
46 [ [ 2 ], [ 3 ], [ 7 ] ],
47 'on_connect_do() worked'
49 eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
50 ok $@, 'Searching for nonexistent table dies';
52 $schema->storage->disconnect();
54 my($connected, $disconnected, @cb_args);
55 ok $schema->connection(
58 on_connect_do => sub { $connected = 1; @cb_args = @_; },
59 on_disconnect_do => sub { $disconnected = 1 },
61 ), 'second connection()';
62 $schema->storage->dbh->do('SELECT 1');
63 ok $connected, 'on_connect_do() called after connect()';
64 ok ! $disconnected, 'on_disconnect_do() not called after connect()';
65 $schema->storage->disconnect();
66 ok $disconnected, 'on_disconnect_do() called after disconnect()';
68 isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook');
72 ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
78 eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
79 ok $@, 'Reading from dropped table fails';
83 sub insert_from_subref {
86 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
87 'INSERT INTO TEST_empty VALUES (7)',