Fix test in t/91debug.t for less ambigious SQL bracketing for 0.08013 release
[dbsrgits/DBIx-Class.git] / t / 91debug.t
CommitLineData
004d31fb 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
cadd7ab8 7use DBIC::SqlMakerTest;
8use DBIC::DebugObj;
004d31fb 9
10my $schema = DBICTest->init_schema();
11
e5d9ee92 12plan tests => 6;
004d31fb 13
14ok ( $schema->storage->debug(1), 'debug' );
15ok ( defined(
16 $schema->storage->debugfh(
17 IO::File->new('t/var/sql.log', 'w')
18 )
19 ),
20 'debugfh'
21 );
22
193195d8 23$schema->storage->debugfh->autoflush(1);
70f39278 24my $rs = $schema->resultset('CD')->search({});
25$rs->count();
26
27my $log = new IO::File('t/var/sql.log', 'r') or die($!);
28my $line = <$log>;
29$log->close();
30ok($line =~ /^SELECT COUNT/, 'Log success');
31
32$schema->storage->debugfh(undef);
33$ENV{'DBIC_TRACE'} = '=t/var/foo.log';
34$rs = $schema->resultset('CD')->search({});
35$rs->count();
36$log = new IO::File('t/var/foo.log', 'r') or die($!);
37$line = <$log>;
38$log->close();
39ok($line =~ /^SELECT COUNT/, 'Log success');
70f39278 40$schema->storage->debugobj->debugfh(undef);
41delete($ENV{'DBIC_TRACE'});
42open(STDERRCOPY, '>&STDERR');
43stat(STDERRCOPY); # nop to get warnings quiet
44close(STDERR);
45eval {
46 $rs = $schema->resultset('CD')->search({});
47 $rs->count();
48};
49ok($@, 'Died on closed FH');
50open(STDERR, '>&STDERRCOPY');
51
e5d9ee92 52# test trace output correctness for bind params
53{
cadd7ab8 54 my ($sql, @bind);
55 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
56 $schema->storage->debug(1);
e5d9ee92 57
58 my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
cadd7ab8 59 is_same_sql_bind (
60 $sql, \@bind,
e9aa5e5d 61 q/SELECT me.cdid, me.artist, me.title, me.year FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) )/,
cadd7ab8 62 [qw/'1' '1' '3'/],
e5d9ee92 63 'got correct SQL with all bind parameters'
64 );
65}
66
004d31fb 671;