fix rounding issues in mssql money tests
[dbsrgits/DBIx-Class-Historic.git] / t / 91debug.t
CommitLineData
004d31fb 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
67e1ac6d 7use DBIC::DebugObj;
949172b0 8use DBIC::SqlMakerTest;
004d31fb 9
10my $schema = DBICTest->init_schema();
11
9b459129 12plan tests => 7;
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{
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 731;