8 my $schema = DBICTest->init_schema();
12 ok ( $schema->storage->debug(1), 'debug' );
14 $schema->storage->debugfh(
15 IO::File->new('t/var/sql.log', 'w')
21 $schema->storage->debugfh->autoflush(1);
22 my $rs = $schema->resultset('CD')->search({});
25 my $log = new IO::File('t/var/sql.log', 'r') or die($!);
28 ok($line =~ /^SELECT COUNT/, 'Log success');
30 $schema->storage->debugfh(undef);
31 $ENV{'DBIC_TRACE'} = '=t/var/foo.log';
32 $rs = $schema->resultset('CD')->search({});
34 $log = new IO::File('t/var/foo.log', 'r') or die($!);
37 ok($line =~ /^SELECT COUNT/, 'Log success');
38 $schema->storage->debugobj->debugfh(undef);
39 delete($ENV{'DBIC_TRACE'});
40 open(STDERRCOPY, '>&STDERR');
41 stat(STDERRCOPY); # nop to get warnings quiet
44 $rs = $schema->resultset('CD')->search({});
47 ok($@, 'Died on closed FH');
48 open(STDERR, '>&STDERRCOPY');
50 # test trace output correctness for bind params
53 $schema->storage->debugcb( sub { $sql = $_[1] } );
55 my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
58 qr/\QSELECT me.cdid, me.artist, me.title, me.year FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'\E/,
59 'got correct SQL with all bind parameters'