line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Query; |
2
|
|
|
|
|
|
|
# ABSTRACT: Simplified abstracted chained DBI subclass |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
377325
|
use 5.008; |
|
2
|
|
|
|
|
14
|
|
5
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
33
|
|
6
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.12'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
2601
|
use DBI 1.40; |
|
2
|
|
|
|
|
29057
|
|
|
2
|
|
|
|
|
103
|
|
11
|
2
|
|
|
2
|
|
797
|
use parent 'DBI'; |
|
2
|
|
|
|
|
482
|
|
|
2
|
|
|
|
|
11
|
|
12
|
|
|
|
|
|
|
*errstr = \*DBI::errstr; |
13
|
|
|
|
|
|
|
our $_dq_parser_cache = {}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _connect { |
16
|
3
|
|
|
3
|
|
8
|
my ( $self, $dsn, $user, $pass, $attr, $connect ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
3
|
100
|
|
|
|
12
|
$attr = ($attr) ? \%$attr : {}; |
19
|
3
|
50
|
|
|
|
14
|
$attr->{PrintError} = 0 unless ( exists $attr->{PrintError} ); |
20
|
3
|
100
|
|
|
|
12
|
$attr->{RaiseError} = 1 unless ( exists $attr->{RaiseError} ); |
21
|
|
|
|
|
|
|
|
22
|
3
|
50
|
|
|
|
34
|
return $self->SUPER::connect( $dsn, $user, $pass, { |
23
|
|
|
|
|
|
|
%$attr, |
24
|
|
|
|
|
|
|
dbi_connect_method => ( $DBI::connect_via eq 'Apache::DBI::connect' ) |
25
|
|
|
|
|
|
|
? 'Apache::DBI::connect' : $connect, |
26
|
|
|
|
|
|
|
} ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub connect { |
30
|
2
|
|
|
2
|
1
|
84
|
my ( $self, $dsn, $user, $pass, $attr ) = @_; |
31
|
2
|
|
|
|
|
9
|
return $self->_connect( $dsn, $user, $pass, $attr, 'connect_cached' ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub connect_uncached { |
35
|
1
|
|
|
1
|
1
|
181
|
my ( $self, $dsn, $user, $pass, $attr ) = @_; |
36
|
1
|
|
|
|
|
5
|
return $self->_connect( $dsn, $user, $pass, $attr, 'connect' ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
package DBIx::Query::_Common; |
43
|
2
|
|
|
2
|
|
429
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
36
|
|
44
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
66
|
|
45
|
2
|
|
|
2
|
|
10
|
use Carp 'croak'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
406
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _param { |
48
|
557
|
|
|
557
|
|
67620
|
my $self = shift; |
49
|
557
|
|
|
|
|
577
|
my $name = shift; |
50
|
|
|
|
|
|
|
|
51
|
557
|
50
|
|
|
|
794
|
return unless ($name); |
52
|
557
|
100
|
|
|
|
1685
|
$self->{'private_dq_stash'}{$name} = shift if (@_); |
53
|
557
|
|
|
|
|
2987
|
return $self->{'private_dq_stash'}{$name}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _try { |
57
|
196
|
|
|
196
|
|
268
|
my ( $self, $cb ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
196
|
|
|
|
|
244
|
local $@; |
60
|
196
|
|
|
|
|
234
|
eval { $cb->() }; |
|
196
|
|
|
|
|
237
|
|
61
|
196
|
50
|
|
|
|
5277
|
if ($@) { |
62
|
0
|
|
|
|
|
0
|
( my $error = $@ ) =~ s/\s*at.+?line \d+\.\s*//; |
63
|
0
|
|
|
|
|
0
|
croak $error; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
package DBIx::Query::db; |
72
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
52
|
|
73
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
50
|
|
74
|
2
|
|
|
2
|
|
1332
|
use SQL::Parser; |
|
2
|
|
|
|
|
73199
|
|
|
2
|
|
|
|
|
96
|
|
75
|
2
|
|
|
2
|
|
842
|
use SQL::Abstract::Complete; |
|
2
|
|
|
|
|
29405
|
|
|
2
|
|
|
|
|
95
|
|
76
|
2
|
|
|
2
|
|
14
|
use Carp 'carp'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
85
|
|
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
2
|
|
11
|
use vars '@ISA'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2811
|
|
79
|
|
|
|
|
|
|
@ISA = qw( DBI::db DBIx::Query::_Common ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub connected { |
82
|
3
|
|
|
3
|
|
12730
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
8
|
my $connection = {}; |
85
|
3
|
|
|
|
|
9
|
@{$connection}{qw( dsn user pass attr )} = @_; |
|
3
|
|
|
|
|
13
|
|
86
|
|
|
|
|
|
|
|
87
|
3
|
|
|
|
|
15
|
$self->_param( 'connection' => $connection ); |
88
|
3
|
|
|
|
|
51
|
$self->_param( 'sql_abstract' => SQL::Abstract::Complete->new ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $dialect = ( ref $connection eq 'HASH' and ref $connection->{attr} eq 'HASH' ) |
91
|
|
|
|
|
|
|
? $connection->{attr}{dq_dialect} |
92
|
3
|
50
|
33
|
|
|
28
|
: undef; |
93
|
3
|
|
50
|
|
|
27
|
$dialect ||= 'ANSI'; |
94
|
|
|
|
|
|
|
|
95
|
3
|
|
|
|
|
28
|
$self->_param( |
96
|
|
|
|
|
|
|
'sql_parser' => SQL::Parser->new( |
97
|
|
|
|
|
|
|
$dialect, { 'RaiseError' => 0, 'PrintError' => 0 } |
98
|
|
|
|
|
|
|
) |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
|
|
14
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub connection { |
105
|
7
|
|
|
7
|
|
6235
|
my $self = shift; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return |
108
|
2
|
|
|
|
|
5
|
( @_ == 0 and wantarray ) ? @{ $self->_param('connection') }{ qw( dsn user pass attr ) } : |
109
|
|
|
|
|
|
|
( @_ == 0 and not wantarray ) ? $self->_param('connection') : |
110
|
1
|
|
|
|
|
4
|
( @_ > 1 and wantarray ) ? @{ $self->_param('connection') }{@_} : |
111
|
1
|
|
|
|
|
4
|
( @_ > 1 and not wantarray ) ? [ @{ $self->_param('connection') }{@_} ] : |
112
|
7
|
100
|
100
|
|
|
59
|
@{ $self->_param('connection') }{@_}; |
|
1
|
100
|
66
|
|
|
3
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _sth_setup { |
116
|
76
|
|
|
76
|
|
121
|
my ( $self, $sql, $attr, $cache_type, $variables ) = @_; |
117
|
|
|
|
|
|
|
|
118
|
76
|
|
|
|
|
80
|
my $sth; |
119
|
|
|
|
|
|
|
$self->_try( sub { |
120
|
76
|
100
|
66
|
76
|
|
486
|
$sth = ( defined $cache_type and $cache_type == -1 ) |
121
|
|
|
|
|
|
|
? $self->SUPER::prepare( $sql, $attr ) |
122
|
|
|
|
|
|
|
: $self->SUPER::prepare_cached( $sql, $attr, $cache_type ); |
123
|
76
|
|
|
|
|
360
|
} ); |
124
|
|
|
|
|
|
|
|
125
|
76
|
|
|
|
|
271
|
return $sth; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _query { |
129
|
75
|
|
|
75
|
|
127
|
my ( $self, $sql, $attr, $cache_type, $variables ) = @_; |
130
|
75
|
|
100
|
|
|
255
|
$cache_type //= 3; |
131
|
|
|
|
|
|
|
|
132
|
75
|
|
|
|
|
144
|
my $sth = $self->_sth_setup( $sql, $attr, $cache_type, $variables ); |
133
|
|
|
|
|
|
|
|
134
|
75
|
|
|
|
|
976
|
$sql =~ s/(\r?\n|\s+)/ /g; |
135
|
75
|
|
|
|
|
439
|
$sql =~ s/^\s+|\s+$//g; |
136
|
|
|
|
|
|
|
|
137
|
75
|
|
|
|
|
169
|
$sth->_param( 'sql' => $sql ); |
138
|
75
|
|
|
|
|
166
|
$sth->_param( 'dq' => $self ); |
139
|
75
|
|
|
|
|
167
|
$sth->_param( 'variables' => $variables ); |
140
|
|
|
|
|
|
|
|
141
|
75
|
|
|
|
|
192
|
return $sth; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub sql { |
145
|
40
|
|
|
40
|
|
3864
|
my ( $self, $sql, $attr, $cache_type, $variables ) = @_; |
146
|
40
|
50
|
|
|
|
81
|
$self->_croak('SQL input missing in sql() call') unless ( length $sql ); |
147
|
40
|
|
|
|
|
83
|
return $self->_query( $sql, $attr, $cache_type, $variables ); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub get { |
151
|
35
|
|
|
35
|
|
1620
|
my ( $self, $tables, $columns, $where, $meta, $attr, $cache_type ) = @_; |
152
|
35
|
|
|
|
|
70
|
my ( $sql, @variables ) = $self->_param('sql_abstract')->select( $tables, $columns, $where, $meta ); |
153
|
35
|
|
|
|
|
7796
|
my $sth = $self->_query( $sql, $attr, $cache_type, \@variables ); |
154
|
|
|
|
|
|
|
|
155
|
35
|
|
|
|
|
201
|
$sth->_param( 'query' => { |
156
|
|
|
|
|
|
|
'tables' => $tables, |
157
|
|
|
|
|
|
|
'columns' => $columns, |
158
|
|
|
|
|
|
|
'where' => $where, |
159
|
|
|
|
|
|
|
'meta' => $meta, |
160
|
|
|
|
|
|
|
'attr' => $attr, |
161
|
|
|
|
|
|
|
'cache_type' => $cache_type, |
162
|
|
|
|
|
|
|
'sql' => $sql, |
163
|
|
|
|
|
|
|
'variables' => \@variables, |
164
|
|
|
|
|
|
|
} ); |
165
|
|
|
|
|
|
|
|
166
|
35
|
|
|
|
|
149
|
return $sth; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub sql_uncached { |
170
|
2
|
|
|
2
|
|
24
|
my ( $self, $sql, $attr, $cache_type, $variables ) = @_; |
171
|
2
|
|
|
|
|
4
|
$cache_type = -1; |
172
|
2
|
|
|
|
|
7
|
return $self->sql( $sql, $attr, $cache_type, $variables ); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub get_uncached { |
176
|
2
|
|
|
2
|
|
27
|
my ( $self, $tables, $columns, $where, $meta, $attr, $cache_type ) = @_; |
177
|
2
|
|
|
|
|
6
|
$cache_type = -1; |
178
|
2
|
|
|
|
|
8
|
return $self->get( $tables, $columns, $where, $meta, $attr, $cache_type ); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub sql_fast { |
182
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
183
|
0
|
|
|
|
|
0
|
carp('sql_fast() is deprecated in favor of sql()'); |
184
|
0
|
|
|
|
|
0
|
return $self->sql(@_); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub get_fast { |
188
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
189
|
0
|
|
|
|
|
0
|
carp('get_fast() is deprecated in favor of get()'); |
190
|
0
|
|
|
|
|
0
|
return $self->get(@_); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub add { |
194
|
2
|
|
|
2
|
|
376
|
my ( $self, $table_name, $params, $attr, $cache_type ) = @_; |
195
|
2
|
|
|
|
|
7
|
my ( $sql, @variables ) = $self->_param('sql_abstract')->insert( $table_name, $params ); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
$self->_try( sub { |
198
|
2
|
|
|
2
|
|
7
|
my $sth = $self->sql( $sql, $attr, $cache_type, \@variables ); |
199
|
2
|
50
|
|
|
|
4
|
$sth->execute( @{ $sth->_param('variables') || [] } ); |
|
2
|
|
|
|
|
7
|
|
200
|
2
|
|
|
|
|
717
|
} ); |
201
|
|
|
|
|
|
|
|
202
|
2
|
|
|
|
|
7
|
my $pk; |
203
|
2
|
|
|
|
|
4
|
eval { |
204
|
|
|
|
|
|
|
$pk = $self->last_insert_id( |
205
|
|
|
|
|
|
|
undef, |
206
|
|
|
|
|
|
|
undef, |
207
|
2
|
|
33
|
|
|
29
|
delete $attr->{'last_insert_table'} || $table_name, |
208
|
|
|
|
|
|
|
undef, |
209
|
|
|
|
|
|
|
$attr, |
210
|
|
|
|
|
|
|
); |
211
|
|
|
|
|
|
|
}; |
212
|
|
|
|
|
|
|
|
213
|
2
|
|
|
|
|
11
|
$self->_param( 'table' => $table_name ); |
214
|
|
|
|
|
|
|
|
215
|
2
|
|
|
|
|
12
|
return $pk; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub rm { |
219
|
2
|
|
|
2
|
|
7
|
my ( $self, $table_name, $params, $attr, $cache_type ) = @_; |
220
|
|
|
|
|
|
|
|
221
|
2
|
|
|
|
|
7
|
my ( $sql, @variables ) = $self->_param('sql_abstract')->delete( $table_name, $params ); |
222
|
2
|
|
|
|
|
350
|
my $sth = $self->sql( $sql, $attr, $cache_type, \@variables ); |
223
|
|
|
|
|
|
|
|
224
|
2
|
|
|
|
|
7
|
$sth->run; |
225
|
2
|
|
|
|
|
11
|
return $self; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub update { |
229
|
2
|
|
|
2
|
|
6
|
my ( $self, $table_name, $params, $where, $attr, $cache_type ) = @_; |
230
|
|
|
|
|
|
|
|
231
|
2
|
|
|
|
|
7
|
my ( $sql, @variables ) = $self->_param('sql_abstract')->update( $table_name, $params, $where ); |
232
|
2
|
|
|
|
|
552
|
my $sth = $self->sql( $sql, $attr, $cache_type, \@variables ); |
233
|
|
|
|
|
|
|
|
234
|
2
|
|
|
|
|
6
|
$sth->run; |
235
|
2
|
|
|
|
|
7
|
return $self; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub get_run { |
239
|
9
|
|
|
9
|
|
13
|
my $self = shift; |
240
|
9
|
|
|
|
|
19
|
my $sth = $self->get(@_); |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
$self->_try( sub { |
243
|
9
|
50
|
|
9
|
|
11
|
$sth->execute( @{ $sth->_param('variables') || [] } ); |
|
9
|
|
|
|
|
14
|
|
244
|
9
|
|
|
|
|
39
|
} ); |
245
|
|
|
|
|
|
|
|
246
|
9
|
|
|
|
|
26
|
return $sth; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub fetch_value { |
250
|
2
|
|
|
2
|
|
422
|
my $self = shift; |
251
|
2
|
|
|
|
|
6
|
my $sth = $self->get_run(@_); |
252
|
2
|
|
|
|
|
5
|
my $value; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
$self->_try( sub { |
255
|
2
|
|
|
2
|
|
18
|
$value = ( $sth->fetchrow_array )[0]; |
256
|
2
|
|
|
|
|
20
|
$sth->finish; |
257
|
2
|
|
|
|
|
10
|
} ); |
258
|
|
|
|
|
|
|
|
259
|
2
|
|
|
|
|
9
|
return $value; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub fetchall_arrayref { |
263
|
4
|
|
|
4
|
|
433
|
my $self = shift; |
264
|
4
|
|
|
|
|
11
|
my $sth = $self->get_run(@_); |
265
|
4
|
|
|
|
|
6
|
my $value; |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
$self->_try( sub { |
268
|
4
|
|
|
4
|
|
34
|
$value = $sth->fetchall_arrayref; |
269
|
4
|
|
|
|
|
236
|
$sth->finish; |
270
|
4
|
|
|
|
|
18
|
} ); |
271
|
|
|
|
|
|
|
|
272
|
4
|
|
|
|
|
17
|
return $value; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub fetchall_hashref { |
276
|
2
|
|
|
2
|
|
393
|
my $self = shift; |
277
|
2
|
|
|
|
|
8
|
my $sth = $self->get_run(@_); |
278
|
2
|
|
|
|
|
4
|
my $value; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
$self->_try( sub { |
281
|
2
|
|
|
2
|
|
11
|
$value = $sth->fetchall_arrayref({}); |
282
|
2
|
|
|
|
|
293
|
$sth->finish; |
283
|
2
|
|
|
|
|
9
|
} ); |
284
|
|
|
|
|
|
|
|
285
|
2
|
|
|
|
|
14
|
return $value; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub fetch_column_arrayref { |
289
|
2
|
|
|
2
|
|
411
|
my $self = shift; |
290
|
2
|
|
|
|
|
5
|
return [ map { $_->[0] } @{ $self->fetchall_arrayref(@_) } ]; |
|
22
|
|
|
|
|
38
|
|
|
2
|
|
|
|
|
6
|
|
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
sub fetchrow_hashref { |
294
|
1
|
|
|
1
|
|
3
|
my ( $self, $sql ) = ( shift, shift ); |
295
|
1
|
50
|
|
|
|
4
|
$self->_croak('SQL input missing in sql() call') unless ( length $sql ); |
296
|
|
|
|
|
|
|
|
297
|
1
|
|
|
|
|
2
|
my ( $variables, $attr, $cache_type ); |
298
|
1
|
50
|
33
|
|
|
6
|
if ( not defined $_[0] or ref $_[0] eq 'HASH' ) { |
299
|
0
|
|
|
|
|
0
|
( $variables, $attr, $cache_type ) = @_; |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
else { |
302
|
1
|
|
|
|
|
3
|
$variables = \@_; |
303
|
|
|
|
|
|
|
} |
304
|
1
|
|
50
|
|
|
6
|
$cache_type //= 3; |
305
|
|
|
|
|
|
|
|
306
|
1
|
|
|
|
|
1
|
my $row; |
307
|
|
|
|
|
|
|
$self->_try( sub { |
308
|
1
|
|
|
1
|
|
4
|
my $sth = $self->_sth_setup( $sql, $attr, $cache_type, $variables ); |
309
|
1
|
|
|
|
|
25
|
$sth->execute(@$variables); |
310
|
1
|
|
|
|
|
20
|
$row = $sth->fetchrow_hashref; |
311
|
1
|
|
|
|
|
6
|
$sth->finish; |
312
|
1
|
|
|
|
|
6
|
} ); |
313
|
|
|
|
|
|
|
|
314
|
1
|
|
|
|
|
7
|
return $row; |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
{ |
321
|
|
|
|
|
|
|
package DBIx::Query::st; |
322
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
64
|
|
323
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
74
|
|
324
|
2
|
|
|
2
|
|
10
|
use Carp 'croak'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
105
|
|
325
|
|
|
|
|
|
|
|
326
|
2
|
|
|
2
|
|
11
|
use vars '@ISA'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
786
|
|
327
|
|
|
|
|
|
|
@ISA = qw( DBI::st DBIx::Query::_Common ); |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub where { |
330
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
331
|
|
|
|
|
|
|
|
332
|
4
|
50
|
|
|
|
6
|
croak('Unable to call where() because upstream query not originated with get()') |
333
|
|
|
|
|
|
|
unless ( $self->_param('query') ); |
334
|
|
|
|
|
|
|
|
335
|
4
|
50
|
33
|
|
|
20
|
croak('where() requires a hashref or an even number of items in a list') |
336
|
|
|
|
|
|
|
if ( ref( $_[0] ) ne 'HASH' and @_ % 2 ); |
337
|
|
|
|
|
|
|
|
338
|
4
|
|
|
|
|
7
|
my $query = $self->_param('query'); |
339
|
4
|
100
|
|
|
|
7
|
$query->{'where'} = { %{ $query->{'where'} || {} }, ( ref( $_[0] ) eq 'HASH' ) ? %{ $_[0] } : @_ }; |
|
4
|
50
|
|
|
|
20
|
|
|
0
|
|
|
|
|
0
|
|
340
|
|
|
|
|
|
|
|
341
|
4
|
|
|
|
|
11
|
return $self->up->get( @{$query}{ qw( tables columns where meta attr cache_type ) } ); |
|
4
|
|
|
|
|
10
|
|
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
sub run { |
345
|
54
|
|
|
54
|
|
73
|
my $self = shift; |
346
|
54
|
|
|
|
|
92
|
my @input = @_; |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
$self->_try( sub { |
349
|
54
|
100
|
|
54
|
|
415
|
$self->execute( (@input) ? @input : @{ $self->_param('variables') || [] } ); |
|
33
|
100
|
|
|
|
55
|
|
350
|
54
|
|
|
|
|
242
|
} ); |
351
|
|
|
|
|
|
|
|
352
|
54
|
|
|
|
|
216
|
return DBIx::Query::_Dq::RowSet->new($self); |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
sub sql { |
356
|
3
|
|
|
3
|
|
11
|
my ( $self, $sql ) = @_; |
357
|
3
|
50
|
|
|
|
9
|
return ($sql) ? $self->_param('dq')->sql($sql) : $self->_param('sql'); |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
sub structure { |
361
|
38
|
|
|
38
|
|
376
|
my $self = shift; |
362
|
|
|
|
|
|
|
|
363
|
38
|
|
|
|
|
58
|
my $structure = $self->_param('structure'); |
364
|
|
|
|
|
|
|
|
365
|
38
|
100
|
|
|
|
146
|
return $structure if ($structure); |
366
|
15
|
50
|
|
|
|
24
|
return if ( $self->_param('no_structure') ); |
367
|
|
|
|
|
|
|
|
368
|
15
|
|
|
|
|
29
|
my $sql = $self->_param('sql'); |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
$DBIx::Query::_dq_parser_cache->{$sql} ||= $self->_param('dq')->_param('sql_parser')->structure if ( |
371
|
15
|
100
|
33
|
|
|
58
|
not $DBIx::Query::_dq_parser_cache->{$sql} and |
|
|
|
66
|
|
|
|
|
372
|
|
|
|
|
|
|
$self->_param('dq')->_param('sql_parser')->parse($sql) |
373
|
|
|
|
|
|
|
); |
374
|
|
|
|
|
|
|
|
375
|
15
|
|
|
|
|
110
|
$self->_param( 'wildcard_column' => 0 ); |
376
|
|
|
|
|
|
|
|
377
|
15
|
50
|
|
|
|
43
|
if ( $DBIx::Query::_dq_parser_cache->{$sql} ) { |
378
|
15
|
|
|
|
|
24
|
my $structure = $DBIx::Query::_dq_parser_cache->{$sql}; |
379
|
15
|
|
|
|
|
22
|
my $column_index = 0; |
380
|
15
|
|
|
|
|
42
|
my %aliases; |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
{ |
383
|
2
|
|
|
2
|
|
13
|
no warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
607
|
|
|
15
|
|
|
|
|
20
|
|
384
|
|
|
|
|
|
|
$structure->{'column_lookup'} = { |
385
|
|
|
|
|
|
|
map { |
386
|
27
|
|
|
|
|
33
|
my $index = $column_index++; |
387
|
27
|
50
|
|
|
|
42
|
$aliases{ $_->{'alias'} } = $index if ( $_->{'alias'} ); |
388
|
27
|
100
|
|
|
|
53
|
$self->_param( 'wildcard_column' => 1 ) if ( $_->{'value'} eq '*' ); |
389
|
27
|
|
|
|
|
75
|
$_->{'value'} => $index; |
390
|
15
|
|
|
|
|
17
|
} @{ $structure->{'column_defs'} } |
|
15
|
|
|
|
|
30
|
|
391
|
|
|
|
|
|
|
}; |
392
|
|
|
|
|
|
|
}; |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
$structure->{'column_invert_lookup'} = { |
395
|
15
|
|
|
|
|
25
|
map { $structure->{'column_lookup'}->{$_} => $_ } keys %{ $structure->{'column_lookup'} } |
|
27
|
|
|
|
|
114
|
|
|
15
|
|
|
|
|
42
|
|
396
|
|
|
|
|
|
|
}; |
397
|
15
|
|
|
|
|
39
|
foreach ( keys %aliases ) { |
398
|
0
|
|
|
|
|
0
|
$structure->{'column_lookup'}{$_} = $aliases{$_}; |
399
|
0
|
|
|
|
|
0
|
$structure->{'column_invert_lookup'}{ $aliases{$_} } = $_; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
|
402
|
15
|
|
|
|
|
33
|
$self->_param( 'structure' => $structure ); |
403
|
15
|
|
|
|
|
94
|
return $structure; |
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
else { |
406
|
0
|
|
|
|
|
0
|
$self->_param( 'no_structure' => 1 ); |
407
|
0
|
|
|
|
|
0
|
return; |
408
|
|
|
|
|
|
|
} |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
sub table { |
412
|
6
|
|
|
6
|
|
18
|
return shift->structure->{'table_names'}[0]; |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
sub _wildcard_column { |
416
|
18
|
|
|
18
|
|
21
|
my $self = shift; |
417
|
|
|
|
|
|
|
|
418
|
18
|
|
|
|
|
29
|
my $wildcard_column = $self->_param('wildcard_column'); |
419
|
18
|
100
|
|
|
|
63
|
return $wildcard_column if ( defined $wildcard_column ); |
420
|
|
|
|
|
|
|
|
421
|
12
|
|
|
|
|
30
|
$self->structure; |
422
|
12
|
|
|
|
|
23
|
return $self->_param('wildcard_column'); |
423
|
|
|
|
|
|
|
} |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
sub up { |
426
|
10
|
|
|
10
|
|
20
|
return shift->_param('dq'); |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
{ |
433
|
|
|
|
|
|
|
package DBIx::Query::_Dq::RowSet; |
434
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
51
|
|
435
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
22
|
|
|
2
|
|
|
|
|
55
|
|
436
|
2
|
|
|
2
|
|
9
|
use Carp 'croak'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1231
|
|
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
sub new { |
439
|
54
|
|
|
54
|
|
96
|
my ( $self, $sth ) = @_; |
440
|
54
|
|
|
|
|
242
|
return bless( { 'sth' => $sth }, $self ); |
441
|
|
|
|
|
|
|
} |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
sub next { |
444
|
17
|
|
|
17
|
|
35
|
my ( $self, $skip ) = @_; |
445
|
17
|
|
100
|
|
|
55
|
$skip ||= 0; |
446
|
|
|
|
|
|
|
|
447
|
17
|
100
|
|
|
|
38
|
my $method = ( $self->{'sth'}->_wildcard_column ) ? 'fetchrow_hashref' : 'fetchrow_arrayref'; |
448
|
|
|
|
|
|
|
|
449
|
17
|
|
|
|
|
20
|
my $value; |
450
|
|
|
|
|
|
|
DBIx::Query::_Common::_try( $self, sub { |
451
|
17
|
|
|
17
|
|
90
|
$self->{'sth'}->fetchrow_arrayref while ( $skip-- ); |
452
|
|
|
|
|
|
|
|
453
|
17
|
100
|
|
|
|
195
|
if ( my $row = $self->{'sth'}->$method ) { |
454
|
16
|
|
|
|
|
77
|
$value = DBIx::Query::_Dq::Row->new( $row, $self ); |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
|
457
|
17
|
|
|
|
|
77
|
} ); |
458
|
|
|
|
|
|
|
|
459
|
17
|
100
|
|
|
|
112
|
return $value if ($value); |
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
sub all { |
463
|
11
|
|
|
11
|
|
17
|
my $self = shift; |
464
|
11
|
|
|
|
|
16
|
my @input = @_; |
465
|
|
|
|
|
|
|
|
466
|
11
|
|
|
|
|
11
|
my $value; |
467
|
|
|
|
|
|
|
DBIx::Query::_Common::_try( $self, sub { |
468
|
11
|
|
|
11
|
|
92
|
$value = $self->{'sth'}->fetchall_arrayref(@input); |
469
|
11
|
|
|
|
|
468
|
$self->{'sth'}->finish; |
470
|
11
|
|
|
|
|
43
|
} ); |
471
|
|
|
|
|
|
|
|
472
|
11
|
|
|
|
|
72
|
return $value; |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
sub each { |
476
|
1
|
|
|
1
|
|
4
|
my ( $self, $code ) = @_; |
477
|
1
|
50
|
|
|
|
3
|
my $method = ( $self->{'sth'}->_wildcard_column ) ? 'fetchrow_hashref' : 'fetchrow_arrayref'; |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
DBIx::Query::_Common::_try( $self, sub { |
480
|
1
|
|
|
1
|
|
14
|
$code->( DBIx::Query::_Dq::Row->new( $_, $self ) ) while ( $_ = $self->{'sth'}->$method ); |
481
|
1
|
|
|
|
|
4
|
$self->{'sth'}->finish; |
482
|
1
|
|
|
|
|
9
|
} ); |
483
|
|
|
|
|
|
|
|
484
|
1
|
|
|
|
|
4
|
return $self; |
485
|
|
|
|
|
|
|
} |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
sub value { |
488
|
15
|
|
|
15
|
|
23
|
my $self = shift; |
489
|
|
|
|
|
|
|
|
490
|
15
|
|
|
|
|
19
|
my @value; |
491
|
|
|
|
|
|
|
DBIx::Query::_Common::_try( $self, sub { |
492
|
15
|
|
|
15
|
|
119
|
@value = $self->{'sth'}->fetchrow_array; |
493
|
15
|
|
|
|
|
61
|
$self->{'sth'}->finish; |
494
|
15
|
|
|
|
|
52
|
} ); |
495
|
|
|
|
|
|
|
|
496
|
15
|
|
|
|
|
40
|
my $wantarray = wantarray; |
497
|
15
|
50
|
|
|
|
37
|
if ( not defined $wantarray ) { |
|
|
100
|
|
|
|
|
|
498
|
0
|
|
|
|
|
0
|
croak('value() must not be called in void context'); |
499
|
|
|
|
|
|
|
} |
500
|
|
|
|
|
|
|
elsif ( not wantarray ) { |
501
|
14
|
50
|
|
|
|
25
|
if ( @value < 2 ) { |
502
|
14
|
|
|
|
|
70
|
return $value[0]; |
503
|
|
|
|
|
|
|
} |
504
|
|
|
|
|
|
|
else { |
505
|
0
|
|
|
|
|
0
|
croak('value() called in scalar context but multiple values fetched'); |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
else { |
509
|
1
|
|
|
|
|
7
|
return @value; |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
} |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
sub first { |
514
|
2
|
|
|
2
|
|
5
|
my ( $self, $type ) = @_; |
515
|
2
|
100
|
|
|
|
7
|
my $method = ( ref $type eq 'HASH' ) ? 'fetchrow_hashref' : 'fetchrow_arrayref'; |
516
|
|
|
|
|
|
|
|
517
|
2
|
|
|
|
|
4
|
my $value; |
518
|
|
|
|
|
|
|
DBIx::Query::_Common::_try( $self, sub { |
519
|
2
|
|
|
2
|
|
20
|
$value = $self->{'sth'}->$method; |
520
|
2
|
|
|
|
|
33
|
$self->{'sth'}->finish; |
521
|
2
|
|
|
|
|
7
|
} ); |
522
|
|
|
|
|
|
|
|
523
|
2
|
|
|
|
|
15
|
return $value; |
524
|
|
|
|
|
|
|
} |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
sub column { |
527
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
528
|
2
|
|
|
|
|
3
|
my @values = map { $_->[0] } @{ ( $self->all )[0] }; |
|
22
|
|
|
|
|
27
|
|
|
2
|
|
|
|
|
5
|
|
529
|
|
|
|
|
|
|
|
530
|
2
|
100
|
|
|
|
15
|
return (wantarray) ? @values : \@values; |
531
|
|
|
|
|
|
|
} |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
sub up { |
534
|
29
|
|
|
29
|
|
56
|
return shift->{'sth'}; |
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
} |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
{ |
541
|
|
|
|
|
|
|
package DBIx::Query::_Dq::Row; |
542
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
543
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
54
|
|
544
|
2
|
|
|
2
|
|
9
|
use Carp 'croak'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1558
|
|
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
sub new { |
547
|
18
|
|
|
18
|
|
36
|
my ( $self, $row, $set ) = @_; |
548
|
18
|
|
|
|
|
65
|
return bless( |
549
|
|
|
|
|
|
|
{ |
550
|
|
|
|
|
|
|
'row' => $row, |
551
|
|
|
|
|
|
|
'set' => $set, |
552
|
|
|
|
|
|
|
}, |
553
|
|
|
|
|
|
|
$self, |
554
|
|
|
|
|
|
|
); |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
sub cell { |
558
|
8
|
|
|
8
|
|
18
|
my ( $self, $index, $new_value ) = @_; |
559
|
8
|
|
|
|
|
19
|
my ( $name, $structure, $value ) = ( $index, $self->up->up->structure, undef ); |
560
|
|
|
|
|
|
|
|
561
|
8
|
50
|
|
|
|
23
|
croak('Query used earlier in chain failed to parse, so cell() cannot be called') |
562
|
|
|
|
|
|
|
unless ( ref($structure) eq 'HASH' ); |
563
|
|
|
|
|
|
|
|
564
|
8
|
100
|
|
|
|
19
|
if ( ref( $self->{'row'} ) eq 'ARRAY' ) { |
565
|
5
|
100
|
|
|
|
31
|
unless ( $index =~ /^\d+$/ ) { |
566
|
4
|
|
|
|
|
7
|
$name = $index; |
567
|
4
|
|
|
|
|
9
|
$index = $structure->{'column_lookup'}{$index}; |
568
|
|
|
|
|
|
|
} |
569
|
5
|
50
|
33
|
|
|
17
|
return undef unless ( defined $index and $index < @{ $self->{'row'} } ); |
|
5
|
|
|
|
|
14
|
|
570
|
5
|
|
|
|
|
13
|
$value = $self->{'row'}[$index]; |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
else { |
573
|
3
|
50
|
|
|
|
10
|
croak('cell() called with integer index but query does not support integer indexing') |
574
|
|
|
|
|
|
|
if ( $index =~ /^\d+$/ ); |
575
|
|
|
|
|
|
|
|
576
|
3
|
50
|
|
|
|
7
|
return undef unless ( exists $self->{'row'}{$index} ); |
577
|
3
|
|
|
|
|
4
|
$value = $self->{'row'}{$index}; |
578
|
|
|
|
|
|
|
} |
579
|
|
|
|
|
|
|
|
580
|
8
|
100
|
|
|
|
17
|
if ( defined $new_value ) { |
581
|
2
|
100
|
|
|
|
5
|
if ( ref( $self->{'row'} ) eq 'ARRAY' ) { |
582
|
1
|
|
|
|
|
2
|
$self->{'row'}[$index] = $new_value; |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
else { |
585
|
1
|
|
|
|
|
2
|
$self->{'row'}{$name} = $new_value; |
586
|
|
|
|
|
|
|
} |
587
|
2
|
|
|
|
|
2
|
$value = $new_value; |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
|
590
|
8
|
|
|
|
|
25
|
return DBIx::Query::_Dq::Cell->new( $name, $value, $index, $self ); |
591
|
|
|
|
|
|
|
} |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
sub each { |
594
|
1
|
|
|
1
|
|
3
|
my ( $self, $code ) = @_; |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
croak('each() called on a row object that does not have columns defined') |
597
|
1
|
50
|
|
|
|
5
|
if ( ref( $self->{'row'} ) ne 'ARRAY' ); |
598
|
|
|
|
|
|
|
|
599
|
1
|
|
|
|
|
3
|
for ( my $i = 0 ; $i < @{ $self->{'row'} } ; $i++ ) { |
|
3
|
|
|
|
|
6
|
|
600
|
|
|
|
|
|
|
$code->( |
601
|
|
|
|
|
|
|
DBIx::Query::_Dq::Cell->new( |
602
|
|
|
|
|
|
|
$self->up->up->structure->{'column_lookup'}{$i}, |
603
|
2
|
|
|
|
|
6
|
$self->{'row'}[$i], |
604
|
|
|
|
|
|
|
$i, $self, |
605
|
|
|
|
|
|
|
) |
606
|
|
|
|
|
|
|
); |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
1
|
|
|
|
|
2
|
return $self; |
610
|
|
|
|
|
|
|
} |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
sub data { |
613
|
11
|
|
|
11
|
|
22
|
my ($self) = @_; |
614
|
|
|
|
|
|
|
|
615
|
11
|
100
|
|
|
|
24
|
if ( ref( $self->{'row'} ) eq 'ARRAY' ) { |
616
|
8
|
|
|
|
|
14
|
my $structure = $self->up->up->structure; |
617
|
8
|
50
|
33
|
|
|
34
|
if ( ref($structure) eq 'HASH' and $structure->{'column_invert_lookup'} ) { |
618
|
|
|
|
|
|
|
return { |
619
|
|
|
|
|
|
|
map { |
620
|
18
|
|
|
|
|
69
|
$structure->{'column_invert_lookup'}->{$_} => $self->{'row'}[$_] |
621
|
8
|
|
|
|
|
13
|
} ( 0 .. scalar( @{ $self->{'row'} } ) - 1 ) |
|
8
|
|
|
|
|
20
|
|
622
|
|
|
|
|
|
|
}; |
623
|
|
|
|
|
|
|
} |
624
|
|
|
|
|
|
|
else { |
625
|
0
|
|
|
|
|
0
|
croak('Unable to parse SQL, therefore data() unavailable; use row() instead'); |
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
else { |
629
|
3
|
|
|
|
|
17
|
return $self->{'row'}; |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
} |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
sub row { |
634
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
635
|
|
|
|
|
|
|
croak('For this particular query, use data() instead') |
636
|
1
|
50
|
|
|
|
5
|
unless ( ref( $self->{'row'} ) eq 'ARRAY' ); |
637
|
1
|
|
|
|
|
5
|
return $self->{'row'}; |
638
|
|
|
|
|
|
|
} |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
sub save { |
641
|
5
|
|
|
5
|
|
11
|
my ( $self, $key, $params, $cache_type ) = @_; |
642
|
|
|
|
|
|
|
|
643
|
5
|
50
|
|
|
|
7
|
croak('save() called without a key or set of keys') unless ($key); |
644
|
|
|
|
|
|
|
|
645
|
5
|
|
|
|
|
9
|
my $data = $self->data; |
646
|
5
|
100
|
|
|
|
12
|
if ( ref($params) eq 'HASH' ) { |
647
|
4
|
|
|
|
|
5
|
$data->{$_} = $params->{$_} foreach ( keys %{$params} ); |
|
4
|
|
|
|
|
15
|
|
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
|
650
|
5
|
|
|
|
|
10
|
my $dq = $self->up->up->up; |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
my ( $sql, @variables ) = $dq->_param('sql_abstract')->update( |
653
|
|
|
|
|
|
|
$self->up->up->table, |
654
|
|
|
|
|
|
|
$data, |
655
|
5
|
50
|
|
|
|
13
|
{ map { $_ => delete $data->{$_} } ( ref($key) ? @{$key} : $key ) }, |
|
5
|
|
|
|
|
26
|
|
|
0
|
|
|
|
|
0
|
|
656
|
|
|
|
|
|
|
); |
657
|
5
|
|
|
|
|
1436
|
my $sth = $dq->sql( $sql, undef, $cache_type, \@variables ); |
658
|
|
|
|
|
|
|
|
659
|
5
|
|
|
|
|
13
|
$sth->run; |
660
|
5
|
|
|
|
|
21
|
return $self; |
661
|
|
|
|
|
|
|
} |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
sub up { |
664
|
29
|
|
|
29
|
|
57
|
return shift->{'set'}; |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
{ |
671
|
|
|
|
|
|
|
package DBIx::Query::_Dq::Cell; |
672
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
43
|
|
673
|
2
|
|
|
2
|
|
17
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
415
|
|
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
sub new { |
676
|
10
|
|
|
10
|
|
24
|
my ( $self, $name, $value, $index, $row ) = @_; |
677
|
10
|
|
|
|
|
53
|
return bless( |
678
|
|
|
|
|
|
|
{ |
679
|
|
|
|
|
|
|
'name' => $name, |
680
|
|
|
|
|
|
|
'value' => $value, |
681
|
|
|
|
|
|
|
'index' => $index, |
682
|
|
|
|
|
|
|
'row' => $row, |
683
|
|
|
|
|
|
|
}, |
684
|
|
|
|
|
|
|
$self, |
685
|
|
|
|
|
|
|
); |
686
|
|
|
|
|
|
|
} |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
sub name { |
689
|
1
|
|
|
1
|
|
8
|
return shift->{'name'}; |
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
sub value { |
693
|
7
|
|
|
7
|
|
16
|
my ( $self, $new_value ) = @_; |
694
|
7
|
50
|
|
|
|
44
|
return ( defined $new_value ) ? $self->up->cell( $self->name, $new_value ) : $self->{'value'}; |
695
|
|
|
|
|
|
|
} |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
sub index { |
698
|
1
|
|
|
1
|
|
5
|
return shift->{'index'}; |
699
|
|
|
|
|
|
|
} |
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
sub save { |
702
|
2
|
|
|
2
|
|
5
|
return shift->up->save(@_); |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
sub up { |
706
|
4
|
|
|
4
|
|
16
|
return shift->{'row'}; |
707
|
|
|
|
|
|
|
} |
708
|
|
|
|
|
|
|
} |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
1; |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
__END__ |