line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PgSQL::Cursor; |
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: Cursor.pm,v 1.5 1998/08/15 15:09:49 goran Exp $ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
9
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9493
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = '0.51'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new |
20
|
|
|
|
|
|
|
{ |
21
|
0
|
|
|
0
|
0
|
|
my ($class,$socket,$name,$query) = @_; |
22
|
0
|
|
|
|
|
|
my $self = {}; |
23
|
0
|
|
|
|
|
|
bless $self,$class; |
24
|
0
|
|
|
|
|
|
$self->{SOCKET} = $socket; |
25
|
0
|
0
|
|
|
|
|
$self->{NAME} = $name if $name; |
26
|
0
|
0
|
|
|
|
|
$self->{QUERY} = $query if $query; |
27
|
0
|
|
|
|
|
|
$self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub exec |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
|
0
|
0
|
|
my ($self, @params) = @_; |
33
|
0
|
|
|
|
|
|
my $sock = $self->{SOCKET}; |
34
|
0
|
|
|
|
|
|
my $query = $self->{QUERY}; |
35
|
0
|
|
|
|
|
|
my $is_select = $query =~ /^\s*select\s/i; |
36
|
0
|
|
|
|
|
|
my $complete = 0; |
37
|
0
|
|
|
|
|
|
$sock->errmsg(0); |
38
|
0
|
|
|
|
|
|
$sock->flush_input; |
39
|
0
|
|
|
|
|
|
for (@params) { $query =~ s/\?/'$_'/; } |
|
0
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
return 0 if !$sock->sendQuery($query); |
41
|
0
|
|
|
|
|
|
$sock->wait(1,0); |
42
|
0
|
|
|
|
|
|
my $lastResult = undef; |
43
|
0
|
|
|
|
|
|
while (1) |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
|
|
|
|
|
my ($result, @rest) = $sock->parseInput; |
46
|
|
|
|
|
|
|
# print STDERR "exec: $result\n" if $result; |
47
|
0
|
0
|
0
|
|
|
|
$complete++ if $result eq 'C' or $result eq 'I'; |
48
|
0
|
0
|
0
|
|
|
|
last if $complete and $result eq 'Z'; |
49
|
0
|
|
|
|
|
|
$lastResult = $result; |
50
|
|
|
|
|
|
|
# last if ($result == PGRES_COPY_IN || $result == PGRES_COPY_OUT); |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
my $err = $sock->errmsg; |
53
|
0
|
0
|
|
|
|
|
return $err ? 0 : 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub execute |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
0
|
0
|
|
shift->exec(@_); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub nfields |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
0
|
0
|
|
my ($self,$val) = @_; |
64
|
0
|
0
|
|
|
|
|
$self->{NFIELDS} = $val if defined $val; |
65
|
0
|
|
|
|
|
|
$self->{NFIELDS}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub fields |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
0
|
|
my ($self,$val) = @_; |
71
|
0
|
0
|
|
|
|
|
$self->{FIELDS} = $val if defined $val; |
72
|
0
|
|
|
|
|
|
$self->{NTUPLES} = 0; |
73
|
0
|
|
|
|
|
|
$self->{COUNT} = 0; |
74
|
0
|
|
|
|
|
|
$self->{FIELDS}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub add |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
0
|
|
my ($self,$tuple) = @_; |
80
|
0
|
|
|
|
|
|
$self->{NTUPLES}++; |
81
|
0
|
|
|
|
|
|
push @{$self->{TUPLES}}, $tuple; |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub fetch |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
87
|
0
|
|
|
|
|
|
my $aref = $self->{TUPLES}; |
88
|
0
|
|
|
|
|
|
my $count = \$self->{COUNT}; |
89
|
0
|
|
0
|
|
|
|
$$count ||= 0; |
90
|
0
|
0
|
|
|
|
|
return 0 unless $$count < $self->{NTUPLES}; |
91
|
0
|
|
|
|
|
|
return $aref->[$$count++]; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub finish |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
97
|
0
|
|
|
|
|
|
$self->fields; |
98
|
0
|
|
|
|
|
|
$self->{NFIELDS} = $self->{NTUPLES} = 0; |
99
|
0
|
|
|
|
|
|
delete $self->{TUPLES}; |
100
|
0
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub bind_param |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
106
|
0
|
|
|
|
|
|
0; # dummy |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub bind_columns |
110
|
|
|
|
|
|
|
{ |
111
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
112
|
0
|
|
|
|
|
|
0; # dummy |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub rows |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
118
|
0
|
|
|
|
|
|
$self->{NTUPLES}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|