| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
use strict; |
|
2
|
69
|
|
|
69
|
|
403
|
use warnings; |
|
|
69
|
|
|
|
|
116
|
|
|
|
69
|
|
|
|
|
1705
|
|
|
3
|
69
|
|
|
69
|
|
347
|
use Carp (); |
|
|
69
|
|
|
|
|
118
|
|
|
|
69
|
|
|
|
|
1392
|
|
|
4
|
69
|
|
|
69
|
|
287
|
use Scalar::Util qw/looks_like_number/; |
|
|
69
|
|
|
|
|
118
|
|
|
|
69
|
|
|
|
|
1022
|
|
|
5
|
69
|
|
|
69
|
|
269
|
use Class::Accessor::Lite ( |
|
|
69
|
|
|
|
|
122
|
|
|
|
69
|
|
|
|
|
3346
|
|
|
6
|
|
|
|
|
|
|
rw => [qw/suppress_object_creation apply_sql_types guess_sql_types/], |
|
7
|
69
|
|
|
|
|
448
|
); |
|
8
|
69
|
|
|
69
|
|
25277
|
use DBI qw(:sql_types); |
|
|
69
|
|
|
|
|
68403
|
|
|
9
|
69
|
|
|
69
|
|
5838
|
|
|
|
69
|
|
|
|
|
123
|
|
|
|
69
|
|
|
|
|
58602
|
|
|
10
|
|
|
|
|
|
|
my ($class, %args) = @_; |
|
11
|
|
|
|
|
|
|
|
|
12
|
61
|
|
|
61
|
1
|
505
|
return bless \%args, $class; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
61
|
|
|
|
|
300
|
|
|
15
|
|
|
|
|
|
|
my $self = shift; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $row; |
|
18
|
58
|
|
|
58
|
1
|
15358
|
if ($self->{sth}) { |
|
19
|
|
|
|
|
|
|
$row = $self->{sth}->fetchrow_hashref; |
|
20
|
58
|
|
|
|
|
77
|
$self->{select_columns} ||= $self->{sth}->{$self->{teng}->{fields_case}}; |
|
21
|
58
|
100
|
|
|
|
190
|
unless ( $row ) { |
|
22
|
57
|
|
|
|
|
1433
|
$self->{sth}->finish; |
|
23
|
57
|
|
66
|
|
|
493
|
$self->{sth} = undef; |
|
24
|
57
|
100
|
|
|
|
232
|
return; |
|
25
|
5
|
|
|
|
|
18
|
} |
|
26
|
5
|
|
|
|
|
48
|
} else { |
|
27
|
5
|
|
|
|
|
15
|
return; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
4
|
if ($self->{suppress_object_creation}) { |
|
31
|
|
|
|
|
|
|
return $row; |
|
32
|
|
|
|
|
|
|
} else { |
|
33
|
52
|
100
|
|
|
|
108
|
$self->_apply_sql_types($row) if $self->{apply_sql_types}; |
|
34
|
4
|
|
|
|
|
13
|
return $self->{row_class}->new( |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
48
|
100
|
|
|
|
177
|
sql => $self->{sql}, |
|
37
|
|
|
|
|
|
|
row_data => $row, |
|
38
|
|
|
|
|
|
|
teng => $self->{teng}, |
|
39
|
|
|
|
|
|
|
table => $self->{table}, |
|
40
|
|
|
|
|
|
|
table_name => $self->{table_name}, |
|
41
|
|
|
|
|
|
|
select_columns => $self->{select_columns}, |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
48
|
|
|
|
|
371
|
|
|
47
|
|
|
|
|
|
|
my ($self, $row) = @_; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
foreach my $column (keys %$row) { |
|
50
|
|
|
|
|
|
|
my $type = $self->{table}->{sql_types}->{$column}; |
|
51
|
11
|
|
|
11
|
|
20
|
if (defined $type) { |
|
52
|
|
|
|
|
|
|
if ( $type == SQL_BIGINT |
|
53
|
11
|
|
|
|
|
32
|
or $type == SQL_BIT |
|
54
|
29
|
|
|
|
|
39
|
or $type == SQL_TINYINT |
|
55
|
29
|
100
|
|
|
|
46
|
or $type == SQL_NUMERIC |
|
|
|
100
|
|
|
|
|
|
|
56
|
27
|
100
|
33
|
|
|
274
|
or $type == SQL_INTEGER |
|
|
|
100
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
57
|
|
|
|
|
|
|
or $type == SQL_SMALLINT |
|
58
|
|
|
|
|
|
|
or $type == SQL_DECIMAL |
|
59
|
|
|
|
|
|
|
or $type == SQL_FLOAT |
|
60
|
|
|
|
|
|
|
or $type == SQL_REAL |
|
61
|
|
|
|
|
|
|
or $type == SQL_DOUBLE |
|
62
|
|
|
|
|
|
|
) { |
|
63
|
|
|
|
|
|
|
$row->{$column} += 0; |
|
64
|
|
|
|
|
|
|
} elsif ($type == SQL_BOOLEAN) { |
|
65
|
|
|
|
|
|
|
if ($self->{teng}->{boolean_value}) { |
|
66
|
|
|
|
|
|
|
if ($row->{$column}) { |
|
67
|
9
|
|
|
|
|
16
|
$row->{$column} = $self->{teng}->{boolean_value}->{true}; |
|
68
|
|
|
|
|
|
|
} else { |
|
69
|
9
|
50
|
|
|
|
47
|
$row->{$column} = $self->{teng}->{boolean_value}->{false}; |
|
70
|
9
|
100
|
|
|
|
17
|
} |
|
71
|
6
|
|
|
|
|
13
|
} else { |
|
72
|
|
|
|
|
|
|
$row->{$column} += 0; |
|
73
|
3
|
|
|
|
|
5
|
} |
|
74
|
|
|
|
|
|
|
} else { |
|
75
|
|
|
|
|
|
|
$row->{$column} .= ''; |
|
76
|
0
|
|
|
|
|
0
|
} |
|
77
|
|
|
|
|
|
|
} elsif ($self->{guess_sql_types}) { |
|
78
|
|
|
|
|
|
|
if (looks_like_number($row->{$column})) { |
|
79
|
9
|
|
|
|
|
71
|
$row->{$column} += 0; |
|
80
|
|
|
|
|
|
|
} else { |
|
81
|
|
|
|
|
|
|
$row->{$column} .= ''; |
|
82
|
1
|
50
|
|
|
|
12
|
} |
|
83
|
1
|
|
|
|
|
3
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
0
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $self = shift; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $result = []; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
if ($self->{sth}) { |
|
92
|
21
|
|
|
21
|
1
|
1023
|
$self->{select_columns} ||= $self->{sth}->{$self->{teng}->{fields_case}}; |
|
93
|
|
|
|
|
|
|
$result = $self->{sth}->fetchall_arrayref(+{}); |
|
94
|
21
|
|
|
|
|
122
|
$self->{sth}->finish; |
|
95
|
|
|
|
|
|
|
$self->{sth} = undef; |
|
96
|
21
|
50
|
|
|
|
158
|
|
|
97
|
21
|
|
33
|
|
|
494
|
if (!$self->{suppress_object_creation}) { |
|
98
|
21
|
|
|
|
|
262
|
$result = [map { |
|
99
|
21
|
|
|
|
|
1925
|
$self->{row_class}->new( |
|
100
|
21
|
|
|
|
|
91
|
{ |
|
101
|
|
|
|
|
|
|
sql => $self->{sql}, |
|
102
|
21
|
50
|
|
|
|
56
|
row_data => $_, |
|
103
|
|
|
|
|
|
|
teng => $self->{teng}, |
|
104
|
21
|
|
|
|
|
51
|
table => $self->{table}, |
|
105
|
|
|
|
|
|
|
table_name => $self->{table_name}, |
|
106
|
|
|
|
|
|
|
select_columns => $self->{select_columns}, |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
) |
|
109
|
|
|
|
|
|
|
} @$result]; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
return wantarray ? @$result : $result; |
|
114
|
85
|
|
|
|
|
412
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
|
117
|
|
|
|
|
|
|
|
|
118
|
21
|
100
|
|
|
|
226
|
=head1 NAME |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Teng::Iterator - Iterator for Teng |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This is an iterator class for L<Teng>. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $itr = Your::Model->search('user',{}); |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my @rows = $itr->all; # get all rows |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# do iteration |
|
133
|
|
|
|
|
|
|
while (my $row = $itr->next) { |
|
134
|
|
|
|
|
|
|
... |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 METHODS |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item $itr = Teng::Iterator->new() |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Create new Teng::Iterator's object. You may not call this method directly. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item my $row = $itr->next(); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Get next row data. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item my @ary = $itr->all; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Get all row data in array. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item $itr->suppress_object_creation($bool) |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Set row object creation mode. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item $itr->apply_sql_types($bool) |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Set column type application mode. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
If column has SQL type and it is numeric, regard it as number and add 0 to the value. |
|
162
|
|
|
|
|
|
|
If column has SQL type and it isn't numeric, regard it as string and add '' to the value. |
|
163
|
|
|
|
|
|
|
If column doesn't have SQL type, the value won't be changed. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item $itr->guess_sql_types($bool) |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
If this is true, this implies apply_sql_types also true. |
|
168
|
|
|
|
|
|
|
If column has no SQL type, it guesses SQL type with its value. |
|
169
|
|
|
|
|
|
|
When column value likes numeric, regard it as number and add 0 to the value. |
|
170
|
|
|
|
|
|
|
If not, regard it as string and add '' to the value. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
|
175
|
|
|
|
|
|
|
|