10 use DBIC::SqlMakerTest;
11 use Path::Class qw/file/;
13 BEGIN { delete @ENV{qw(DBIC_TRACE DBIC_TRACE_PROFILE DBICTEST_SQLITE_USE_FILE)} }
15 my $schema = DBICTest->init_schema();
17 my $lfn = file("t/var/sql-$$.log");
21 # make sure we are testing the vanilla debugger and not ::PrettyPrint
22 $schema->storage->debugobj(DBIx::Class::Storage::Statistics->new);
24 ok ( $schema->storage->debug(1), 'debug' );
25 $schema->storage->debugfh($lfn->openw);
26 $schema->storage->debugfh->autoflush(1);
27 $schema->resultset('CD')->count;
29 my @loglines = $lfn->slurp;
30 is (@loglines, 1, 'one line of log');
31 like($loglines[0], qr/^SELECT COUNT/, 'File log via debugfh success');
33 $schema->storage->debugfh(undef);
36 local $ENV{DBIC_TRACE} = "=$lfn";
39 $schema->resultset('CD')->count;
41 my $schema2 = DBICTest->init_schema(no_deploy => 1);
42 $schema2->storage->_do_query('SELECT 1'); # _do_query() logs via standard mechanisms
44 my @loglines = $lfn->slurp;
45 is(@loglines, 2, '2 lines of log');
46 like($loglines[0], qr/^SELECT COUNT/, 'Env log from schema1 success');
47 like($loglines[1], qr/^SELECT 1:/, 'Env log from schema2 success');
49 $schema->storage->debugobj->debugfh(undef)
56 open(STDERRCOPY, '>&STDERR');
59 $schema->resultset('CD')->search({})->count;
60 } 'Died on closed FH';
62 open(STDERR, '>&STDERRCOPY');
64 # test trace output correctness for bind params
67 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
69 my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
72 "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) )",
74 'got correct SQL with all bind parameters (debugcb)'
77 @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
80 "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'"],
81 'got correct SQL with all bind parameters (debugobj)'