| 1 | package DBIx::ProcedureCall::PostgreSQL; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub __run_function{ | ||||||||||||||||||||||||||
|
Subroutine
__run_function: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 12 | 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 | ▶ | if ( $attr->{'fetch'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | if (@_ == 1 and ref $_[0] eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= 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 | ▶ | if ($attr->{table}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | my $sql = "select * from $name("; | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | $sql .= join (',' , map ({ '?'} @_ )); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 0 | $sql .= ')'; | |||||||||||||||||||||||||||
| 36 | # prepare | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $sql = $attr->{cached} ? $dbh->prepare_cached($sql) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | if (@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | $sql .= '(' . join (',' , map ({ '?'} @_ )) . ')'; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | $sql .= ';'; | |||||||||||||||||||||||||||
| 52 | # print $sql; | ||||||||||||||||||||||||||||
| 53 | # prepare | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $sql = $attr->{cached} ? $dbh->prepare_cached($sql) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | # there are no procedures, only void functions | ||||||||||||||||||||||||||||
| 68 | 2 | *__run_procedure = \&__run_function; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub __close{ | ||||||||||||||||||||||||||
|
Subroutine
__close: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 73 | 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 | 2 | 1; | |||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||