PgSQL.pm

filter: Statementstmt 13.7% 37 / 269 Branchbran 2.0% 2 / 96 Conditioncond 8.2% 5 / 61 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 17.5% 10 / 57 Podpod 2.0% 1 / 50 totaltotal 9.7% 55 / 565 CC 71 SCAR 43.5
CC
71
Cov
10%
parseInput
272.0
new
208.9
handshake
72.0
CRAP 77.1
↑ Summary PgSQL/Cursor.pm »
1 package PgSQL;
2  
3 # This perl module is Copyright (c) 1998 Göran Thyni, Sweden.
4 # All rights reserved.
5 # You may distribute under the terms of either
6 # the GNU General Public License version 2 (or later)
7 # or the Artistic License, as specified in the Perl README file.
8 #
9 # $Id: PgSQL.pm,v 1.5 1998/08/15 15:08:39 goran Exp $
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use PgSQL::Cursor;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use IO::Socket::UNIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use vars qw (@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 $VERSION = '0.51';
21  
22 1 @ISA = ('IO::Socket::UNIX');
23  
24 0 ▶sub PG_PROTOCOL_LATEST { 0x00020000; }
Subroutine PG_PROTOCOL_LATEST: not called CC=1 SCAR=6.9
Pod undocumented
25  
26 1 my $EnvironmentOptions =
27 {
28 "PGDATESTYLE" => "datestyle",
29 "PGTZ" => "timezone",
30 "PGCLIENTENCODING" => "client_encoding",
31 "PGCOSTHEAP" => "cost_heap",
32 "PGCOSTINDEX" => "cost_index",
33 "PGRPLANS" => "r_plans",
34 "PGGEQO" => "geqo",
35 };
36  
37 0 ▶sub STATUS_OK {1}
Subroutine STATUS_OK: not called CC=1 SCAR=6.9
Pod undocumented
38 0 ▶sub STATUS_ERROR {0}
Subroutine STATUS_ERROR: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 0 ▶sub PGRES_EMPTY_QUERY {0}
Subroutine PGRES_EMPTY_QUERY: not called CC=1 SCAR=6.9
Pod undocumented
41 0 ▶sub PGRES_COMMAND_OK {1}
Subroutine PGRES_COMMAND_OK: not called CC=1 SCAR=6.9
Pod undocumented
42 0 ▶sub PGRES_TUPLES_OK {2}
Subroutine PGRES_TUPLES_OK: not called CC=1 SCAR=6.9
Pod undocumented
43 0 ▶sub PGRES_COPY_OUT {'G'}
Subroutine PGRES_COPY_OUT: not called CC=1 SCAR=6.9
Pod undocumented
44 0 ▶sub PGRES_COPY_IN {'H'}
Subroutine PGRES_COPY_IN: not called CC=1 SCAR=6.9
Pod undocumented
45 0 ▶sub PGRES_BAD_RESPONSE {5}
Subroutine PGRES_BAD_RESPONSE: not called CC=1 SCAR=6.9
Pod undocumented
46 0 ▶sub PGRES_NONFATAL_ERROR {6}
Subroutine PGRES_NONFATAL_ERROR: not called CC=1 SCAR=6.9
Pod undocumented
47 0 ▶sub PGRES_FATAL_ERROR {7}
Subroutine PGRES_FATAL_ERROR: not called CC=1 SCAR=6.9
Pod undocumented
48  
49 2 ▶sub DEF_PGPORT { 5432; }
Subroutine DEF_PGPORT: called CC=1 SCAR=0.0
Pod undocumented
50 0 ▶sub DEF_PGTTY { ''; }
Subroutine DEF_PGTTY: not called CC=1 SCAR=6.9
Pod undocumented
51 0 ▶sub DEF_PGOPTIONS { ''; }
Subroutine DEF_PGOPTIONS: not called CC=1 SCAR=6.9
Pod undocumented
52  
53 0 ▶sub AUTH_REQ_OK {0}
Subroutine AUTH_REQ_OK: not called CC=1 SCAR=6.9
Pod undocumented
54 0 ▶sub AUTH_REQ_PASSWORD {3}
Subroutine AUTH_REQ_PASSWORD: not called CC=1 SCAR=6.9
Pod undocumented
55 0 ▶sub AUTH_REQ_CRYPT {4}
Subroutine AUTH_REQ_CRYPT: not called CC=1 SCAR=6.9
Pod undocumented
56  
57 sub UNIXSOCK_PATH
58 1 ▶ {
Subroutine UNIXSOCK_PATH: called CC=1 SCAR=0.0
Pod undocumented
59 1 my $href = shift;
60 1 '/tmp/.s.PGSQL.' . $href->{Port};
61 }
62  
63  
64 sub new
65 1 ▶ {
Subroutine new: called CC=19 SCAR=53.4
Pod documented
66 1 my ($class, %args) = @_;
67 1 ▶ my $host = $args{Host} || $ENV{PGHOST};
Condition33%1/3
$args{'Host'} || $ENV{'PGHOST'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$args{'Host'} || $ENV{'PGHOST'}
$args{'Host'} $ENV{'PGHOST'}
Truth table33%1/3
A || B
A= $args{'Host'}B= $ENV{'PGHOST'}
ABresult
1X1
011
000
68 1 ▶ my $port = $args{Port} || $ENV{PGPORT} || &DEF_PGPORT;
Condition33%2/6
$args{'Port'} || $ENV{'PGPORT'} || &DEF_PGPORT
l!l&&r!l&&!r
010
$args{"Port"} or $ENV{"PGPORT"}
l!l&&r!l&&!r
001
MC/DC0%0/3
$args{'Port'} || $ENV{'PGPORT'} || &DEF_PGPORT
$args{"Port"} $ENV{"PGPORT"} &DEF_PGPORT
Truth table25%1/4
A or B || C
A= $args{"Port"}B= $ENV{"PGPORT"}C= &DEF_PGPORT
ABCresult
1XX1
01X1
0011
0000
69 1 ▶ $args{Port} ||= DEF_PGPORT;
Condition33%1/3
$args{"Port"} ||= DEF_PGPORT()
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"Port"} ||= DEF_PGPORT()
$args{"Port"} DEF_PGPORT()
Truth table33%1/3
A ||= B
A= $args{"Port"}B= DEF_PGPORT()
ABresult
1X1
011
000
70 1 ▶ if ($host)
Branch: 1 branch
BranchTrueFalseTotal
if ($host) { } 0 1 1
71 {
72 0 $args{PeerAddr} = "${host}:${port}";
73 0 @ISA = qw (IO::Socket::INET);
74 }
75 else
76 {
77 1 ▶ $args{Peer} ||= UNIXSOCK_PATH(\%args);
Condition33%1/3
$args{"Peer"} ||= UNIXSOCK_PATH(\%args)
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"Peer"} ||= UNIXSOCK_PATH(\%args)
$args{"Peer"} UNIXSOCK_PATH(\%args)
Truth table33%1/3
A ||= B
A= $args{"Peer"}B= UNIXSOCK_PATH(\%args)
ABresult
1X1
011
000
78 }
79 1 my $self = $class->SUPER::new(%args);
80 1 ▶ if ($self)
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 0 1 1
81 {
82 0 ▶ ${*$self}{DBNAME} = $args{DBName} || $ENV{PGDATABASE} || '';
Condition0%0/5
$args{'DBName'} || $ENV{'PGDATABASE'} || ''
l!l
00
$args{"DBName"} or $ENV{"PGDATABASE"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'DBName'} || $ENV{'PGDATABASE'} || ''
$args{"DBName"} $ENV{"PGDATABASE"}
Truth table0%0/3
A or B
A= $args{"DBName"}B= $ENV{"PGDATABASE"}
ABresult
1X1
011
000
83 0 ${*$self}{PGHOST} = $host;
84 0 ${*$self}{PGPORT} = $port;
85 0 ▶ ${*$self}{PGPORT} = $args{Tty} || $ENV{PGTTY} || &DEF_PGTTY;
Condition0%0/6
$args{'Tty'} || $ENV{'PGTTY'} || &DEF_PGTTY
l!l&&r!l&&!r
000
$args{"Tty"} or $ENV{"PGTTY"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'Tty'} || $ENV{'PGTTY'} || &DEF_PGTTY
$args{"Tty"} $ENV{"PGTTY"} &DEF_PGTTY
Truth table0%0/4
A or B || C
A= $args{"Tty"}B= $ENV{"PGTTY"}C= &DEF_PGTTY
ABCresult
1XX1
01X1
0011
0000
86 0 ${*$self}{PGOPTIONS} =
87 0 ▶ $args{Options} || $ENV{PGOPTIONS} || &DEF_PGOPTIONS;
Condition0%0/6
$args{'Options'} || $ENV{'PGOPTIONS'} || &DEF_PGOPTIONS
l!l&&r!l&&!r
000
$args{"Options"} or $ENV{"PGOPTIONS"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'Options'} || $ENV{'PGOPTIONS'} || &DEF_PGOPTIONS
$args{"Options"} $ENV{"PGOPTIONS"} &DEF_PGOPTIONS
Truth table0%0/4
A or B || C
A= $args{"Options"}B= $ENV{"PGOPTIONS"}C= &DEF_PGOPTIONS
ABCresult
1XX1
01X1
0011
0000
88 0 ▶ ${*$self}{PGUSER} = $args{User} || $ENV{PGUSER} || ${*$self}{DBNAME};
Condition0%0/6
$args{'User'} || $ENV{'PGUSER'} || do { *$self }->{'DBNAME'}
l!l&&r!l&&!r
000
$args{"User"} or $ENV{"PGUSER"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'User'} || $ENV{'PGUSER'} || do { *$self }->{'DBNAME'}
$args{"User"} $ENV{"PGUSER"} do { *$self }->{'DBNAME'}
Truth table0%0/4
A or B || C
A= $args{"User"}B= $ENV{"PGUSER"}C= do { *$self }->{'DBNAME'}
ABCresult
1XX1
01X1
0011
0000
89 0 ▶ ${*$self}{PGPASS} = $args{Password} || $ENV{PGPASS} || '';
Condition0%0/5
$args{'Password'} || $ENV{'PGPASS'} || ''
l!l
00
$args{"Password"} or $ENV{"PGPASS"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'Password'} || $ENV{'PGPASS'} || ''
$args{"Password"} $ENV{"PGPASS"}
Truth table0%0/3
A or B
A= $args{"Password"}B= $ENV{"PGPASS"}
ABresult
1X1
011
000
90 0 $self->blocking(0);
91 0 eval { $self->handshake; };
92 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
93 {
94 0 $self->close;
95 0 warn $@;
96 0 return undef;
97 }
98 0 $self->setenv();
99 }
100 1 $self;
101 }
102  
103  
104 sub handshake
105 0 ▶ {
Subroutine handshake: not called CC=8 SCAR=42.8
Pod undocumented
106 0 my $self = shift;
107 0 ▶ unless ($self->packetSend($self->startup_packet))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->packetSend($self->startup_packet)) 0 0 0
108 {
109 0 die "handshake: couldn't send startup packet:errno=$!\n";
110 }
111 0 while (1)
112 {
113 0 ▶ last if $self->wait(1,0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->wait(1, 0) 0 0 0
114 0 my $resp = $self->getc;
115 0 ▶ die $self->getline() if ($resp eq 'E');
Branch: 1 branch
BranchTrueFalseTotal
if $resp eq "E" 0 0 0
116 0 ▶ die "connectDB() -- expected authentication request\n" if $resp ne 'R';
Branch: 1 branch
BranchTrueFalseTotal
if $resp ne "R" 0 0 0
117 0 my $areq = $self->getint(4);
118 0 my $salt = 0;
119 0 ▶ if ($areq == AUTH_REQ_CRYPT)
Branch: 1 branch
BranchTrueFalseTotal
if ($areq == AUTH_REQ_CRYPT()) 0 0 0
120 {
121 0 ▶ next if $self->pqGetnchar($salt, 4);
Branch: 1 branch
BranchTrueFalseTotal
if $self->pqGetnchar($salt, 4) 0 0 0
122 # FIXME, this does not work, I think!
123 }
124 0 $self->sendauth($areq);
125 0 $self->flush;
126 0 ▶ last if ($areq == AUTH_REQ_OK);
Branch: 1 branch
BranchTrueFalseTotal
if $areq == AUTH_REQ_OK() 0 0 0
127 }
128 }
129  
130 sub setenv
131 0 ▶ {
Subroutine setenv: not called CC=4 SCAR=30.0
Pod undocumented
132 0 my $self = shift;
133 0 for my $eo (keys %$EnvironmentOptions)
134 {
135 0 my $val = $ENV{$eo};
136 0 ▶ if ($val)
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
137 {
138 0 my $setQuery = sprintf("SET %s = '%.60s'", $eo->pgName, $val);
139 0 ▶ $setQuery = sprintf("SET %s = default", $eo->pgName)
Branch: 1 branch
BranchTrueFalseTotal
if $val eq "default" 0 0 0
140 if $val eq "default";
141 0 my $res = $self->do($setQuery);
142 }
143 }
144 }
145  
146  
147 sub close
148 0 ▶{
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
149 0 my $self = shift;
150 0 ▶ if ($self->opened)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opened) 0 0 0
151 {
152 0 local $SIG{PIPE} = 'IGNORE';
153 0 $self->print('X');
154 0 $self->flush;
155 0 $self->flush_input;
156 0 $self->SUPER::close;
157 }
158 }
159  
160 sub packetSend
161 0 ▶ {
Subroutine packetSend: not called CC=4 SCAR=30.0
Pod undocumented
162 0 my ($self,$buf,$len) = @_;
163 0 ▶ return STATUS_ERROR unless $self->putint(4 + $len, 4); # size
Branch: 1 branch
BranchTrueFalseTotal
unless $self->putint(4 + $len, 4) 0 0 0
164 0 ▶ return STATUS_ERROR unless $self->write($buf, $len);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->write($buf, $len) 0 0 0
165 0 ▶ return STATUS_ERROR unless $self->flush;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->flush 0 0 0
166 0 STATUS_OK;
167 }
168  
169 sub startup_packet
170 0 ▶ {
Subroutine startup_packet: not called CC=1 SCAR=6.9
Pod undocumented
171 0 my $self = shift;
172 0 my $len = 4 + 64 + 32 + 64 + 64 + 64;
173 my $packet = pack('Na64a32a64a64a64',
174 $self->PG_PROTOCOL_LATEST,
175 0 ${*$self}{DBNAME},
176 0 ${*$self}{PGUSER},
177 0 ${*$self}{PGOPTIONS},
178 '',
179 0 ${*$self}{PGTTY});
180 0 ($packet,$len);
181 }
182  
183 sub getint
184 0 ▶{
Subroutine getint: not called CC=2 SCAR=17.9
Pod undocumented
185 0 my ($self, $sz) = @_;
186 0 my $value;
187 0 $self->read($value,$sz);
188 0 ▶ my @a = unpack($sz == 4 ? 'N' : 'n', $value);
Branch: 1 branch
BranchTrueFalseTotal
$sz == 4 ? : 0 0 0
189 0 return $a[0];
190 }
191  
192 sub putint
193 0 ▶{
Subroutine putint: not called CC=2 SCAR=17.9
Pod undocumented
194 0 my ($self, $value, $sz) = @_;
195 0 ▶ $self->write(pack($sz == 4 ? 'N' : 'n', $value), $sz);
Branch: 1 branch
BranchTrueFalseTotal
$sz == 4 ? : 0 0 0
196 }
197  
198 sub wait
199 0 ▶ {
Subroutine wait: not called CC=7 SCAR=40.3
Pod undocumented
200 0 my ($self,$forRead,$forWrite) = @_;
201 # loop in case select returns EINTR
202 # for (;;)
203 {
204 0 my $sel = IO::Select->new;
205 0 ▶ $sel->add($self) if ($forRead || $forWrite);
Branch: 1 branch
BranchTrueFalseTotal
if $forRead or $forWrite 0 0 0
Condition0%0/3
$forRead or $forWrite
l!l&&r!l&&!r
000
MC/DC0%0/2
$forRead or $forWrite
$forRead $forWrite
Truth table0%0/3
A or B
A= $forReadB= $forWrite
ABresult
1X1
011
000
206 0 ▶ last if (($forRead && $sel->can_read) || ($forWrite && $sel->can_write));
Branch: 1 branch
BranchTrueFalseTotal
if $forRead and $sel->can_read or $forWrite and $sel->can_write 0 0 0
Condition0%0/9
$forRead and $sel->can_read or $forWrite and $sel->can_write
l!l&&r!l&&!r
000
$forRead and $sel->can_read
!ll&&!rl&&r
000
$forWrite and $sel->can_write
!ll&&!rl&&r
000
MC/DC0%0/4
$forRead and $sel->can_read or $forWrite and $sel->can_write
$forRead $sel->can_read $forWrite $sel->can_write
Truth table0%0/7
A and B or C and D
A= $forReadB= $sel->can_readC= $forWriteD= $sel->can_write
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
207 # next if ($errno == EINTR);
208 # return EOF;
209 }
210 0 return 0;
211 }
212  
213  
214 sub sendauth
215 0 ▶ {
Subroutine sendauth: not called CC=3 SCAR=24.8
Pod undocumented
216 0 my ($self, $areq, $hostname, $password, $errmsg) = @_;
217 0 ▶ return STATUS_OK if $areq == AUTH_REQ_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $areq == AUTH_REQ_OK() 0 0 0
218 0 ▶ die "sendauth: no password supplied\n" if (!$password);
Branch: 1 branch
BranchTrueFalseTotal
unless $password 0 0 0
219 # if (pg_password_sendauth(conn, password, areq) != STATUS_OK)
220 {
221 0 die "fe_sendauth: error sending password authentication\n";
222 }
223 0 return STATUS_OK;
224 }
225  
226  
227 sub do
228 0 ▶ {
Subroutine do: not called CC=3 SCAR=24.8
Pod undocumented
229 0 my ($self, $query) = @_;
230 0 my $is_select = $query =~ /^\s*select\s/i;
231 0 my $sth = $self->prepare($query);
232 0 my $stat = $sth->exec;
233 0 ▶ undef $sth unless $stat;
Branch: 1 branch
BranchTrueFalseTotal
unless $stat 0 0 0
234 0 ▶ return $sth if $is_select;
Branch: 1 branch
BranchTrueFalseTotal
if $is_select 0 0 0
235 0 return $stat;
236 }
237  
238 sub prepare
239 0 ▶ {
Subroutine prepare: not called CC=1 SCAR=6.9
Pod undocumented
240 0 my ($self, $query) = @_;
241 0 ${*$self}{CURSOR} = PgSQL::Cursor->new($self, undef, $query);
242 0 ${*$self}{CURSOR};
243 }
244  
245 sub sendQuery
246 0 ▶{
Subroutine sendQuery: not called CC=2 SCAR=17.9
Pod undocumented
247 0 my ($self, $query) = @_;
248 0 $self->flush_input;
249 0 ▶ return 0 unless $self->print('Q' . $query . "\0");
Branch: 1 branch
BranchTrueFalseTotal
unless $self->print('Q' . $query . "\000") 0 0 0
250 0 $self->flush;
251 0 return 1;
252 }
253  
254 sub flush_input
255 0 ▶ {
Subroutine flush_input: not called CC=2 SCAR=17.9
Pod undocumented
256 0 my $self = shift;
257 0 ▶ while (1) { last unless $self->parseInput; }
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parseInput 0 0 0
258 }
259  
260  
261 # parseInput: if appropriate, parse input data from backend
262 # until input is exhausted or a stopping state is reached.
263 # Note that this function will NOT attempt to read more data from the backend.
264  
265 sub parseInput
266 0 ▶ {
Subroutine parseInput: not called CC=16 SCAR=56.1
Pod undocumented
267 0 my ($self) = @_;
268 # Loop to parse successive complete messages available in the buffer.
269 # OK to try to read a message type code.
270 0 my $id = $self->getc;
271 0 ▶ return unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 0 0
272 0 ▶ return if $id eq "\0";
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "\0" 0 0 0
273 # NOTIFY and NOTICE messages can happen in any state besides COPY OUT;
274 # always process them right away.
275 0 ▶ return ($id, $self->getNotify) if $id eq 'A';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "A" 0 0 0
276 0 ▶ return ($id, $self->getNotice) if $id eq 'N';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "N" 0 0 0
277 0 ▶ return ($id, $self->getCompleted) if $id eq 'C';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "C" 0 0 0
278 0 ▶ return ($id, $self->getError) if $id eq 'E';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "E" 0 0 0
279 0 ▶ return ($id) if $id eq 'Z';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "Z" 0 0 0
280 0 ▶ return ($id, $self->getc) if $id eq 'I';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "I" 0 0 0
281 0 ▶ return ($id, $self->getint(4), $self->getint(4)) if $id eq 'K';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "K" 0 0 0
282 0 ▶ return ($id, $self->getCursor) if $id eq 'P'; # cursor
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "P" 0 0 0
283 0 ▶ return ($id, $self->getRowDescr) if $id eq 'T';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "T" 0 0 0
284 0 ▶ return ($id, $self->getTuple(0)) if $id eq 'D';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "D" 0 0 0
285 0 ▶ return ($id, $self->getTuple(1)) if $id eq 'B';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "B" 0 0 0
286 0 ▶ return ($id, $self->getCopyIn) if $id eq 'G';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "G" 0 0 0
287 0 ▶ return ($id, $self->getCopyOut) if $id eq 'H';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "H" 0 0 0
288 0 die "unknown protocol character '$id' (" . $id .
289 ") read from backend. " .
290 "(The protocol character is the first character the " .
291 "backend sends in response to a query it receives).\n";
292 }
293  
294 sub getNotify
295 0 ▶ {
Subroutine getNotify: not called CC=1 SCAR=6.9
Pod undocumented
296 0 my $self = shift;
297 0 my $i = $self->getint(4);
298 0 my $note = $self->gets;
299 0 $self->trace("NOTIFY: $i / $note");
300 0 $note;
301 }
302  
303 sub getNotice
304 0 ▶ {
Subroutine getNotice: not called CC=1 SCAR=6.9
Pod undocumented
305 0 my $self = shift;
306 0 my $note = $self->gets;
307 0 $self->trace("$note");
308 0 $note;
309 }
310  
311 sub getCompleted
312 0 ▶ {
Subroutine getCompleted: not called CC=1 SCAR=6.9
Pod undocumented
313 # local $/ = 0;
314 0 my $self = shift;
315 0 my $note = $self->xgets;
316 0 $self->trace("COMPELETED: $note");
317 0 $note;
318 }
319  
320 sub getError
321 0 ▶ {
Subroutine getError: not called CC=1 SCAR=6.9
Pod undocumented
322 0 my $self = shift;
323 0 my $note = $self->gets;
324 0 die $note;
325 }
326  
327 sub getCursor
328 0 ▶ {
Subroutine getCursor: not called CC=1 SCAR=6.9
Pod undocumented
329 0 my $self = shift;
330 0 my $note = $self->xgets;
331 0 $self->trace("CURSOR: $note");
332 # ${*$self}{CURSOR} = PgSQL::Cursor->new($self,$note,undef);
333 # ${*$self}{CURSOR};
334 0 $note;
335 }
336  
337 sub getCopyIn
338 0 ▶ {
Subroutine getCopyIn: not called CC=1 SCAR=6.9
Pod undocumented
339 0 my $self = shift;
340 0 $self->trace("COPY_IN");
341 }
342  
343 sub getCoyout
344 0 ▶ {
Subroutine getCoyout: not called CC=1 SCAR=6.9
Pod undocumented
345 0 my $self = shift;
346 0 $self->trace("COPY_OUT");
347 }
348
349 sub getRowDescr
350 0 ▶ {
Subroutine getRowDescr: not called CC=3 SCAR=24.8
Pod undocumented
351 0 my $self = shift;
352 0 my ($i,@s,@oids,@typs,@sz);
353 0 my $nfields = $self->getint(2);
354 0 $self->trace("ROWDESCR: $nfields fields");
355 0 ▶ for ($i = 0; $i < $nfields; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $nfields) 0 0 0
356 {
357 0 my $s = $self->xgets;
358 0 my $typ = $self->getint(4);
359 0 my $sz = $self->getint(2);
360 0 my $oid = $self->getint(4);
361 0 push @s, $s;
362 0 push @oids, $oid;
363 0 push @typs, $typ;
364 0 push @sz, unpack("s",pack("s", $sz));
365 0 $self->trace(sprintf("\t%s SIZE:%d TYPE:%d MODIFER:%d",
366 $s, $sz, $typ, $oid));
367 }
368 0 ▶ my $sth = ${*$self}{CURSOR} || PgSQL::Cursor->new($self,undef,undef);
Condition0%0/3
do { *$self }->{'CURSOR'} || 'PgSQL::Cursor'->new($self, undef, undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
do { *$self }->{'CURSOR'} || 'PgSQL::Cursor'->new($self, undef, undef)
do { *$self }->{'CURSOR'} 'PgSQL::Cursor'->new($self, undef, undef)
Truth table0%0/3
A || B
A= do { *$self }->{'CURSOR'}B= 'PgSQL::Cursor'->new($self, undef, undef)
ABresult
1X1
011
000
369 0 $sth->{NAME} = \@s;
370 0 $sth->{TYPE} = \@typs;
371 0 $sth->{SIZE} = \@sz;
372 0 $sth->nfields($nfields);
373 0 $nfields;
374 }
375  
376 sub getTuple
377 0 ▶ {
Subroutine getTuple: not called CC=4 SCAR=25.5
Pod undocumented
378 0 my ($self, $binary) = @_;
379 0 my ($nullbits, $i, $mapbytes);
380 0 my $nfields = ${*$self}{CURSOR}->nfields;
381 {
382 0 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.2
383 0 $mapbytes = $nfields / 8;
384 0 ▶ $mapbytes++ if $nfields % 8;
Branch: 1 branch
BranchTrueFalseTotal
if $nfields % 8 0 0 0
385 }
386 0 $self->read($nullbits, $mapbytes);
387 0 $self->trace("ROW:");
388 0 my $a = [];
389 0 ▶ for ($i = 0; $i < $nfields; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $nfields) 0 0 0
390 {
391 1 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
392 0 my ($sz,$value) = (0,'NULL');
393 0 my $bit = (ord(substr($nullbits, $i / 8, 1)) >> (7 - ($i % 8))) & 1;
394 0 ▶ if ($bit)
Branch: 1 branch
BranchTrueFalseTotal
if ($bit) 0 0 0
395 {
396 0 $sz = $self->getint(4) - 4;
397 0 $self->read($value, $sz);
398 }
399 0 $self->trace("\tTUPLE ($sz):\t$value");
400 0 push @$a, $value;
401 }
402 0 my $sth = ${*$self}{CURSOR};
403 0 $sth->add($a);
404 }
405  
406 sub xgets
407 0 ▶ {
Subroutine xgets: not called CC=3 SCAR=24.8
Pod undocumented
408 0 my $self = shift;
409 0 my $s = '';
410 0 while (1)
411 {
412 0 $_ = $self->getc;
413 0 ▶ last if int($_) == 0 and $_ eq "\0";
Branch: 1 branch
BranchTrueFalseTotal
if int $_ == 0 and $_ eq "\0" 0 0 0
Condition0%0/3
int $_ == 0 and $_ eq "\0"
!ll&&!rl&&r
000
MC/DC0%0/2
int $_ == 0 and $_ eq "\0"
int $_ == 0 $_ eq "\0"
Truth table0%0/3
A and B
A= int $_ == 0B= $_ eq "\0"
ABresult
0X0
100
111
414 0 $s .= $_;
415 }
416 0 return $s;
417 }
418  
419 sub begin
420 0 ▶ {
Subroutine begin: not called CC=1 SCAR=6.9
Pod undocumented
421 0 shift->do("BEGIN");
422 }
423  
424 sub commit
425 0 ▶ {
Subroutine commit: not called CC=1 SCAR=6.9
Pod undocumented
426 0 shift->do("COMMIT");
427 }
428  
429 sub rollback
430 0 ▶ {
Subroutine rollback: not called CC=1 SCAR=6.9
Pod undocumented
431 0 shift->do("ROLLBACK");
432 }
433  
434 sub ping
435 0 ▶ {
Subroutine ping: not called CC=1 SCAR=6.9
Pod undocumented
436 0 my $self = shift;
437 0 $self->do(' ');
438 }
439  
440 sub errmsg
441 0 ▶ {
Subroutine errmsg: not called CC=2 SCAR=17.9
Pod undocumented
442 0 my $self = shift;
443 0 my $msg = shift;
444 0 ▶ if (defined $msg) { ${*$self}{ERRMSG} = $msg; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $msg) 0 0 0
445 0 ${*$self}{ERRMSG};
446 }
447  
448 sub trace
449 0 ▶{
Subroutine trace: not called CC=2 SCAR=17.9
Pod undocumented
450 0 my ($self, @msgs) = @_;
451 0 my $lvl = ${*$self}{TRACE};
452 0 ▶ print STDERR @msgs,"\n" if $lvl;
Branch: 1 branch
BranchTrueFalseTotal
if $lvl 0 0 0
453 }
454  
455 sub debug
456 0 ▶ {
Subroutine debug: not called CC=1 SCAR=6.9
Pod undocumented
457 0 my ($self, $lvl) = @_;
458 0 ${*$self}{TRACE} = $lvl;
459 }
460  
461 1 1;
462  
463  
↑ Summary PgSQL/Cursor.pm »