Commit | Line | Data |
004d31fb |
1 | use strict; |
f54428ab |
2 | use warnings; |
004d31fb |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
67e1ac6d |
7 | use DBIC::DebugObj; |
949172b0 |
8 | use DBIC::SqlMakerTest; |
c9d29bb2 |
9 | use Path::Class qw/file/; |
004d31fb |
10 | |
11 | my $schema = DBICTest->init_schema(); |
12 | |
004d31fb |
13 | |
14 | ok ( $schema->storage->debug(1), 'debug' ); |
c9d29bb2 |
15 | $schema->storage->debugfh(file('t/var/sql.log')->openw); |
004d31fb |
16 | |
193195d8 |
17 | $schema->storage->debugfh->autoflush(1); |
70f39278 |
18 | my $rs = $schema->resultset('CD')->search({}); |
19 | $rs->count(); |
20 | |
c9d29bb2 |
21 | my $log = file('t/var/sql.log')->openr; |
70f39278 |
22 | my $line = <$log>; |
23 | $log->close(); |
24 | ok($line =~ /^SELECT COUNT/, 'Log success'); |
25 | |
26 | $schema->storage->debugfh(undef); |
27 | $ENV{'DBIC_TRACE'} = '=t/var/foo.log'; |
28 | $rs = $schema->resultset('CD')->search({}); |
29 | $rs->count(); |
c9d29bb2 |
30 | $log = file('t/var/foo.log')->openr; |
70f39278 |
31 | $line = <$log>; |
32 | $log->close(); |
33 | ok($line =~ /^SELECT COUNT/, 'Log success'); |
70f39278 |
34 | $schema->storage->debugobj->debugfh(undef); |
35 | delete($ENV{'DBIC_TRACE'}); |
36 | open(STDERRCOPY, '>&STDERR'); |
37 | stat(STDERRCOPY); # nop to get warnings quiet |
38 | close(STDERR); |
39 | eval { |
40 | $rs = $schema->resultset('CD')->search({}); |
41 | $rs->count(); |
42 | }; |
43 | ok($@, 'Died on closed FH'); |
44 | open(STDERR, '>&STDERRCOPY'); |
45 | |
e5d9ee92 |
46 | # test trace output correctness for bind params |
47 | { |
af6aac2d |
48 | my ($sql, @bind); |
49 | $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); |
e5d9ee92 |
50 | |
51 | my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } ); |
9b459129 |
52 | is_same_sql_bind( |
af6aac2d |
53 | $sql, \@bind, |
0491b597 |
54 | "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) )", |
af6aac2d |
55 | [qw/'1' '1' '3'/], |
9b459129 |
56 | 'got correct SQL with all bind parameters (debugcb)' |
57 | ); |
58 | |
9b459129 |
59 | @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } ); |
60 | is_same_sql_bind( |
61 | $sql, \@bind, |
42a7de49 |
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'"], |
9b459129 |
63 | 'got correct SQL with all bind parameters (debugobj)' |
e5d9ee92 |
64 | ); |
65 | } |
66 | |
c9d29bb2 |
67 | done_testing; |