File Coverage

blib/lib/SQL/Abstract/FromQuery/Oracle.pm
Criterion Covered Total %
statement 29 29 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 8 8 100.0
pod 0 4 0.0
total 41 46 89.1


line stmt bran cond sub pod time code
1             package SQL::Abstract::FromQuery::Oracle;
2            
3 2     2   1068 use strict;
  2         4  
  2         51  
4 2     2   10 use warnings;
  2         4  
  2         49  
5 2     2   10 use parent 'SQL::Abstract::FromQuery';
  2         4  
  2         14  
6 2     2   118 use UNIVERSAL::DOES qw/does/;
  2         3  
  2         695  
7            
8             our $time_fmt = q{HH24:MI:SS};
9             our $datetime_fmt_ISO = qq{YYYY-MM-DD"T"$time_fmt};
10            
11             #======================================================================
12             # override actions hooked to the grammar
13             #======================================================================
14            
15             sub date {
16 11     11 0 406 my ($self, $h) = @_;
17            
18 11         42 my $date = $self->next::method($h); # returns date in ISO format YYYY-MM-DD
19            
20             # datetime format is OK for a date without time, Oracle accepts it
21 11         42 return \ ["TO_DATE(?, '$datetime_fmt_ISO')", $date];
22             }
23            
24            
25             sub time {
26 2     2 0 58 my ($self, $h) = @_;
27            
28 2         6 my $time = $self->next::method($h); # returns time in ISO format HH:MM:SS
29 2         8 return \ ["TO_DATE(?, '$time_fmt')", $time];
30             }
31            
32            
33             sub datetime {
34 1     1 0 31 my ($self, $h) = @_;
35            
36             # hack : we remove the "TO_DATE()" parts before calling the parent method ...
37             # and then re-inject the "TO_DATE()" on the global result
38            
39 1         2 $_ = @{$$_}[1] for @{$h}{qw/date time/}; # just keep the bind values
  1         3  
  2         4  
40            
41 1         3 my $datetime = $self->next::method($h); # returns dt as YYYY-MM-DDTHH:MM:SS
42            
43 1         6 return \ ["TO_DATE(?, '$datetime_fmt_ISO')", $datetime];
44             }
45            
46            
47            
48             #======================================================================
49             # override finalization callback
50             #======================================================================
51            
52            
53             sub finalize {
54 2     2 0 8 my ($self, $result) = @_;
55            
56             # if to_date(..) was used without any comparison operator, we must add
57             # an '=' because SQL::Abstract won't do it automatically for values
58             # of shape \[..] (i.e. literal SQL with placeholders and bind values)
59 2         8 foreach my $val (values %$result) {
60 7 100 66     84 if (does($val, 'REF') && does($$val, 'ARRAY')) {
61 4         171 $$val->[0] =~ s/^TO_DATE/= TO_DATE/;
62             }
63             }
64            
65 2         12 return $self->next::method($result);
66             }
67            
68            
69            
70             1; # End of SQL::Abstract::FromQuery::Oracle
71            
72             __END__