10 use DBIC::SqlMakerTest;
11 use Path::Class qw/file/;
13 my $schema = DBICTest->init_schema();
15 my $lfn = file('t/var/sql.log');
19 # make sure we are testing the vanilla debugger and not ::PrettyPrint
20 $schema->storage->debugobj(DBIx::Class::Storage::Statistics->new);
22 ok ( $schema->storage->debug(1), 'debug' );
23 $schema->storage->debugfh($lfn->openw);
24 $schema->storage->debugfh->autoflush(1);
25 $schema->resultset('CD')->count;
27 my @loglines = $lfn->slurp;
28 is (@loglines, 1, 'one line of log');
29 like($loglines[0], qr/^SELECT COUNT/, 'File log via debugfh success');
31 $schema->storage->debugfh(undef);
34 local $ENV{DBIC_TRACE} = "=$lfn";
37 $schema->resultset('CD')->count;
39 my $schema2 = DBICTest->init_schema(no_deploy => 1);
40 $schema2->storage->_do_query('SELECT 1'); # _do_query() logs via standard mechanisms
42 my @loglines = $lfn->slurp;
43 is(@loglines, 2, '2 lines of log');
44 like($loglines[0], qr/^SELECT COUNT/, 'Env log from schema1 success');
45 like($loglines[1], qr/^SELECT 1:/, 'Env log from schema2 success');
47 $schema->storage->debugobj->debugfh(undef)
50 open(STDERRCOPY, '>&STDERR');
53 $schema->resultset('CD')->search({})->count;
54 } 'Died on closed FH';
56 open(STDERR, '>&STDERRCOPY');
58 # test trace output correctness for bind params
61 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
63 my @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 ?) )",
68 'got correct SQL with all bind parameters (debugcb)'
71 @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
74 "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'"],
75 'got correct SQL with all bind parameters (debugobj)'