File Coverage

blib/lib/DBIx/ProcedureCall/PostgreSQL.pm
Criterion Covered Total %
statement 9 44 20.4
branch 0 14 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod n/a
total 12 66 18.1


line stmt bran cond sub pod time code
1             package DBIx::ProcedureCall::PostgreSQL;
2              
3 2     2   48521 use strict;
  2         4  
  2         69  
4 2     2   13 use warnings;
  2         4  
  2         759  
5              
6             our $VERSION = '0.08';
7              
8              
9              
10              
11             sub __run_function{
12 0     0     shift;
13 0           my $dbh = shift;
14 0           my $name = shift;
15 0           my $attr = shift;
16 0           my $params;
17            
18             # any fetch implies a table function)
19 0 0         if ( $attr->{'fetch'} ) {
20 0           $attr->{'table'} = 1;
21             }
22            
23             # if there is one more arg and it is a hashref , then we use with named parameters
24 0 0 0       if (@_ == 1 and ref $_[0] eq 'HASH') {
25 0           die "PostgreSQL does not support named parameters, use positional parameters in your call to '$name'. \n";
26             }
27             # otherwise they are positional parameters
28            
29             # table functions
30 0 0         if ($attr->{table}){
31 0           my $sql = "select * from $name(";
32 0 0         if (@_){
33 0           $sql .= join (',' , map ({ '?'} @_ ));
  0            
34             }
35 0           $sql .= ')';
36             # prepare
37 0 0         $sql = $attr->{cached} ? $dbh->prepare_cached($sql)
38             : $dbh->prepare($sql);
39             # bind
40 0           DBIx::ProcedureCall::__bind_params($sql, 1, \@_);
41             # execute
42 0           $sql->execute;
43 0           return $sql;
44             }
45            
46            
47 0           my $sql = "select $name";
48 0 0         if (@_){
49 0           $sql .= '(' . join (',' , map ({ '?'} @_ )) . ')';
  0            
50             }
51 0           $sql .= ';';
52             # print $sql;
53             # prepare
54 0 0         $sql = $attr->{cached} ? $dbh->prepare_cached($sql)
55             : $dbh->prepare($sql);
56             # bind
57 0           DBIx::ProcedureCall::__bind_params($sql, 1, \@_);
58            
59             #execute
60 0           $sql->execute;
61 0           my ($r) = $sql->fetchrow_array;
62 0           return $r;
63             }
64              
65             {
66 2     2   16 no strict 'refs';
  2         4  
  2         250  
67             # there are no procedures, only void functions
68             *__run_procedure = \&__run_function;
69             }
70              
71              
72             sub __close{
73 0     0     shift;
74 0           my $sth = shift;
75 0           my $conn = $sth->{Database};
76 0           my $sql = $conn->prepare('BEGIN close :curref; END;');
77 0           $sql->bind_param(":curref", $sth, {ora_type => DBD::Oracle::ORA_RSET()});
78 0           $sql->execute;
79             }
80              
81              
82              
83             1;
84             __END__