line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::QueryCursor; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
29
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
177
|
|
4
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
172
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
26
|
use Abstract::Meta::Class ':all'; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
830
|
|
7
|
6
|
|
|
6
|
|
32
|
use Carp 'confess'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
290
|
|
8
|
6
|
|
|
6
|
|
29
|
use base 'DBIx::SQLHandler'; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
500
|
|
9
|
6
|
|
|
6
|
|
28
|
use vars qw($VERSION); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
2960
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = 0.03; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
DBIx::QueryCursor - Database cursor handler |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use DBIx::QueryCursor; |
20
|
|
|
|
|
|
|
my $cursor = new DBIx::QueryCursor( |
21
|
|
|
|
|
|
|
connection => $connection, |
22
|
|
|
|
|
|
|
sql => "SELECT * FROM emp WHERE ename = ?" |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
my $result_set = $cursor->execute(['Smith']); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
if($cursor->fetch()) { |
27
|
|
|
|
|
|
|
$ename = result_set->{ENAME}; |
28
|
|
|
|
|
|
|
... do some stuff |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
or |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use DBIx::Connection; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $cursor = $connection->query_cursor( |
37
|
|
|
|
|
|
|
sql => "SELECT * FROM emp WHERE ename = ?" |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Class that represents database cursor. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 attributes |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=over |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item result_set |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Fetch resultset. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has '$.result_set'; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item rows |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Number of rows retrieved since last execution. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has '$.rows'; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=back |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 methods |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=over |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item columns |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Function return list of column from current cursor |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub columns { |
79
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
80
|
0
|
|
|
|
|
|
\@{$self->sth->{NAME_lc}} |
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item execute |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Executes statements, takes bind parameters as ARRAY ref, optionaly resul set as reference(HASH, SCALAR, ARRAY) |
87
|
|
|
|
|
|
|
Returns result set. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub execute { |
92
|
0
|
|
|
0
|
1
|
|
my ($self, $bind_params, $result_set) = @_; |
93
|
0
|
|
0
|
|
|
|
$result_set ||= {}; |
94
|
0
|
|
|
|
|
|
$self->set_result_set($result_set); |
95
|
0
|
0
|
|
|
|
|
$self->finish if $self->rows; |
96
|
0
|
|
|
|
|
|
$self->SUPER::execute(@$bind_params); |
97
|
0
|
|
|
|
|
|
$self->bind_columns($result_set); |
98
|
0
|
|
|
|
|
|
$self->set_rows(0); |
99
|
0
|
|
|
|
|
|
$result_set; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item iterator |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Returns the cursor itarator, on each iteration database error is checked. |
106
|
|
|
|
|
|
|
For instance sub query returned more then error exception is capture here. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub iterator { |
111
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
112
|
0
|
|
|
|
|
|
my $sth = $self->sth; |
113
|
0
|
|
|
|
|
|
my $dbh = $self->connection->dbh; |
114
|
|
|
|
|
|
|
sub { |
115
|
0
|
|
|
0
|
|
|
my $result = $sth->fetch(); |
116
|
0
|
|
|
|
|
|
$self->set_rows($self->rows + 1); |
117
|
0
|
0
|
|
|
|
|
confess $self->error_handler |
118
|
|
|
|
|
|
|
if $dbh->errstr; |
119
|
0
|
|
|
|
|
|
$result; |
120
|
0
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item fetch |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Move cursor to next result. |
127
|
|
|
|
|
|
|
Returns true if a row was fetched or false if no more results exist. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub fetch { |
132
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
133
|
0
|
|
|
|
|
|
my $dbh = $self->connection->dbh; |
134
|
0
|
|
|
|
|
|
my $has_result = $self->sth->fetch; |
135
|
0
|
0
|
|
|
|
|
$self->error_handler |
136
|
|
|
|
|
|
|
if $dbh->errstr; |
137
|
0
|
|
|
|
|
|
$self->set_rows($self->rows + 1); |
138
|
0
|
0
|
|
|
|
|
$has_result ? (wantarray ? @$has_result : $has_result) : (); |
|
|
0
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item finish |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Signals that the cursor will not be used again. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub finish { |
149
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
150
|
0
|
0
|
|
|
|
|
$self->sth->finish if $self->sth; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |