8 use DBIC::SqlMakerTest;
10 my $schema = DBICTest->init_schema();
14 ok ( $schema->storage->debug(1), 'debug' );
16 $schema->storage->debugfh(
17 IO::File->new('t/var/sql.log', 'w')
23 $schema->storage->debugfh->autoflush(1);
24 my $rs = $schema->resultset('CD')->search({});
27 my $log = new IO::File('t/var/sql.log', 'r') or die($!);
30 ok($line =~ /^SELECT COUNT/, 'Log success');
32 $schema->storage->debugfh(undef);
33 $ENV{'DBIC_TRACE'} = '=t/var/foo.log';
34 $rs = $schema->resultset('CD')->search({});
36 $log = new IO::File('t/var/foo.log', 'r') or die($!);
39 ok($line =~ /^SELECT COUNT/, 'Log success');
40 $schema->storage->debugobj->debugfh(undef);
41 delete($ENV{'DBIC_TRACE'});
42 open(STDERRCOPY, '>&STDERR');
43 stat(STDERRCOPY); # nop to get warnings quiet
46 $rs = $schema->resultset('CD')->search({});
49 ok($@, 'Died on closed FH');
50 open(STDERR, '>&STDERRCOPY');
52 # test trace output correctness for bind params
54 my ($sql, @bind) = ('');
55 $schema->storage->debugcb( sub { $sql = $_[1] } );
57 my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
60 "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'", [],
61 'got correct SQL with all bind parameters (debugcb)'
64 $schema->storage->debugcb(undef);
65 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
66 @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
69 "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? )", ["'1'", "'1'", "'3'"],
70 'got correct SQL with all bind parameters (debugobj)'