9 use DBIC::SqlMakerTest;
10 use Path::Class qw/file/;
12 my $schema = DBICTest->init_schema();
14 # make sure we are testing the vanilla debugger and not ::PrettyPrint
15 $schema->storage->debugobj(DBIx::Class::Storage::Statistics->new);
17 ok ( $schema->storage->debug(1), 'debug' );
18 $schema->storage->debugfh(file('t/var/sql.log')->openw);
20 $schema->storage->debugfh->autoflush(1);
21 my $rs = $schema->resultset('CD')->search({});
24 my $log = file('t/var/sql.log')->openr;
27 like($line, qr/^SELECT COUNT/, 'Log success');
29 $schema->storage->debugfh(undef);
30 $ENV{'DBIC_TRACE'} = '=t/var/foo.log';
31 $rs = $schema->resultset('CD')->search({});
33 $log = file('t/var/foo.log')->openr;
36 like($line, qr/^SELECT COUNT/, 'Log success');
37 $schema->storage->debugobj->debugfh(undef);
38 delete($ENV{'DBIC_TRACE'});
40 open(STDERRCOPY, '>&STDERR');
41 stat(STDERRCOPY); # nop to get warnings quiet
44 $rs = $schema->resultset('CD')->search({});
46 } 'Died on closed FH';
48 open(STDERR, '>&STDERRCOPY');
50 # test trace output correctness for bind params
53 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
55 my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
58 "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) )",
60 'got correct SQL with all bind parameters (debugcb)'
63 @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
66 "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'"],
67 'got correct SQL with all bind parameters (debugobj)'