8 use DBIC::SqlMakerTest;
9 use Path::Class qw/file/;
11 my $schema = DBICTest->init_schema();
14 ok ( $schema->storage->debug(1), 'debug' );
15 $schema->storage->debugfh(file('t/var/sql.log')->openw);
17 $schema->storage->debugfh->autoflush(1);
18 my $rs = $schema->resultset('CD')->search({});
21 my $log = file('t/var/sql.log')->openr;
24 ok($line =~ /^SELECT COUNT/, 'Log success');
26 $schema->storage->debugfh(undef);
27 $ENV{'DBIC_TRACE'} = '=t/var/foo.log';
28 $rs = $schema->resultset('CD')->search({});
30 $log = file('t/var/foo.log')->openr;
33 ok($line =~ /^SELECT COUNT/, 'Log success');
34 $schema->storage->debugobj->debugfh(undef);
35 delete($ENV{'DBIC_TRACE'});
36 open(STDERRCOPY, '>&STDERR');
37 stat(STDERRCOPY); # nop to get warnings quiet
40 $rs = $schema->resultset('CD')->search({});
43 ok($@, 'Died on closed FH');
44 open(STDERR, '>&STDERRCOPY');
46 # test trace output correctness for bind params
49 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
51 my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
54 "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) )",
56 'got correct SQL with all bind parameters (debugcb)'
59 @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
62 "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'"],
63 'got correct SQL with all bind parameters (debugobj)'