Commit | Line | Data |
004d31fb |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
67e1ac6d |
7 | use DBIC::DebugObj; |
949172b0 |
8 | use DBIC::SqlMakerTest; |
004d31fb |
9 | |
10 | my $schema = DBICTest->init_schema(); |
11 | |
9b459129 |
12 | plan tests => 7; |
004d31fb |
13 | |
14 | ok ( $schema->storage->debug(1), 'debug' ); |
15 | ok ( 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 |
24 | my $rs = $schema->resultset('CD')->search({}); |
25 | $rs->count(); |
26 | |
27 | my $log = new IO::File('t/var/sql.log', 'r') or die($!); |
28 | my $line = <$log>; |
29 | $log->close(); |
30 | ok($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(); |
39 | ok($line =~ /^SELECT COUNT/, 'Log success'); |
70f39278 |
40 | $schema->storage->debugobj->debugfh(undef); |
41 | delete($ENV{'DBIC_TRACE'}); |
42 | open(STDERRCOPY, '>&STDERR'); |
43 | stat(STDERRCOPY); # nop to get warnings quiet |
44 | close(STDERR); |
45 | eval { |
46 | $rs = $schema->resultset('CD')->search({}); |
47 | $rs->count(); |
48 | }; |
49 | ok($@, 'Died on closed FH'); |
50 | open(STDERR, '>&STDERRCOPY'); |
51 | |
e5d9ee92 |
52 | # test trace output correctness for bind params |
53 | { |
af6aac2d |
54 | my ($sql, @bind); |
55 | $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); |
e5d9ee92 |
56 | |
57 | my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } ); |
9b459129 |
58 | is_same_sql_bind( |
af6aac2d |
59 | $sql, \@bind, |
60 | "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'", |
61 | [qw/'1' '1' '3'/], |
9b459129 |
62 | 'got correct SQL with all bind parameters (debugcb)' |
63 | ); |
64 | |
9b459129 |
65 | @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } ); |
66 | is_same_sql_bind( |
67 | $sql, \@bind, |
42a7de49 |
68 | "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 |
69 | 'got correct SQL with all bind parameters (debugobj)' |
e5d9ee92 |
70 | ); |
71 | } |
72 | |
004d31fb |
73 | 1; |