line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ActiveRecord::Simple::Find; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
171
|
use 5.010; |
|
11
|
|
|
|
|
34
|
|
4
|
11
|
|
|
11
|
|
54
|
use strict; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
765
|
|
5
|
11
|
|
|
11
|
|
44
|
use warnings; |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
261
|
|
6
|
11
|
|
|
11
|
|
55
|
use vars qw/$AUTOLOAD/; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
398
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
54
|
use Carp; |
|
11
|
|
|
|
|
15
|
|
|
11
|
|
|
|
|
548
|
|
9
|
11
|
|
|
11
|
|
54
|
use Storable qw/freeze/; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
367
|
|
10
|
11
|
|
|
11
|
|
48
|
use Module::Load; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
51
|
|
11
|
|
|
|
|
|
|
|
12
|
11
|
|
|
11
|
|
1524
|
use parent 'ActiveRecord::Simple'; |
|
11
|
|
|
|
|
1024
|
|
|
11
|
|
|
|
|
73
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $MAXIMUM_LIMIT = 100_000_000_000; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
83
|
|
|
83
|
1
|
179
|
my ($self_class, $class, @param) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#my $self = $class->new(); |
22
|
83
|
|
|
|
|
202
|
my $self = bless { class => $class } => $self_class; |
23
|
|
|
|
|
|
|
|
24
|
83
|
50
|
|
|
|
442
|
my $table_name = ($self->{class}->can('_get_table_name')) ? $self->{class}->_get_table_name : undef; |
25
|
83
|
100
|
|
|
|
300
|
my $pkey = ($self->{class}->can('_get_primary_key')) ? $self->{class}->_get_primary_key : undef; |
26
|
|
|
|
|
|
|
|
27
|
83
|
|
50
|
|
|
357
|
$self->{prep_select_fields} //= []; |
28
|
83
|
|
50
|
|
|
269
|
$self->{prep_select_from} //= []; |
29
|
83
|
|
50
|
|
|
253
|
$self->{prep_select_where} //= []; |
30
|
|
|
|
|
|
|
|
31
|
83
|
|
|
|
|
120
|
my ($fields, $from, $where); |
32
|
|
|
|
|
|
|
|
33
|
83
|
100
|
100
|
|
|
467
|
if (!ref $param[0] && scalar @param == 1) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
34
|
15
|
|
|
|
|
35
|
$fields = qq/"$table_name".*/; |
35
|
15
|
|
|
|
|
33
|
$from = qq/"$table_name"/; |
36
|
15
|
|
|
|
|
29
|
$where = qq/"$table_name"."$pkey" = ?/; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$self->{BIND} = \@param |
39
|
15
|
|
|
|
|
53
|
} |
40
|
|
|
|
|
|
|
elsif (!ref $param[0] && scalar @param == 0) { |
41
|
32
|
|
|
|
|
66
|
$fields = qq/"$table_name".*/; |
42
|
32
|
|
|
|
|
50
|
$from = qq/"$table_name"/; |
43
|
|
|
|
|
|
|
|
44
|
32
|
|
|
|
|
49
|
$self->{BIND} = undef; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif (ref $param[0] && ref $param[0] eq 'HASH') { |
47
|
|
|
|
|
|
|
# find many by params |
48
|
26
|
|
|
|
|
64
|
my ($bind, $condition_pairs) = $self->parse_hash($param[0]); |
49
|
|
|
|
|
|
|
|
50
|
26
|
|
|
|
|
80
|
my $where_str = join q/ AND /, @$condition_pairs; |
51
|
|
|
|
|
|
|
|
52
|
26
|
|
|
|
|
48
|
$fields = qq/"$table_name".*/; |
53
|
26
|
|
|
|
|
42
|
$from = qq/"$table_name"/; |
54
|
26
|
|
|
|
|
36
|
$where = $where_str; |
55
|
|
|
|
|
|
|
|
56
|
26
|
|
|
|
|
54
|
$self->{BIND} = $bind; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif (ref $param[0] && ref $param[0] eq 'ARRAY') { |
59
|
|
|
|
|
|
|
# find many by primary keys |
60
|
3
|
|
|
|
|
8
|
my $whereinstr = join ', ', @{ $param[0] }; |
|
3
|
|
|
|
|
10
|
|
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
8
|
$fields = qq/"$table_name".*/; |
63
|
3
|
|
|
|
|
6
|
$from = qq/"$table_name"/; |
64
|
3
|
|
|
|
|
8
|
$where = qq/"$table_name"."$pkey" IN ($whereinstr)/; |
65
|
|
|
|
|
|
|
|
66
|
3
|
|
|
|
|
6
|
$self->{BIND} = undef; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
|
|
|
|
|
|
# find many by condition |
70
|
7
|
|
|
|
|
11
|
my $wherestr = shift @param; |
71
|
|
|
|
|
|
|
|
72
|
7
|
|
|
|
|
19
|
$fields = qq/"$table_name".*/; |
73
|
7
|
|
|
|
|
14
|
$from = qq/"$table_name"/; |
74
|
7
|
|
|
|
|
10
|
$where = $wherestr; |
75
|
|
|
|
|
|
|
|
76
|
7
|
|
|
|
|
15
|
$self->{BIND} = \@param; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
83
|
50
|
|
|
|
164
|
push @{ $self->{prep_select_fields} }, $fields if $fields; |
|
83
|
|
|
|
|
166
|
|
80
|
83
|
50
|
|
|
|
139
|
push @{ $self->{prep_select_from} }, $from if $from; |
|
83
|
|
|
|
|
129
|
|
81
|
83
|
100
|
|
|
|
137
|
push @{ $self->{prep_select_where} }, $where if $where; |
|
51
|
|
|
|
|
78
|
|
82
|
|
|
|
|
|
|
|
83
|
83
|
|
|
|
|
262
|
return $self; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub count { |
87
|
7
|
|
|
7
|
1
|
12
|
my $inv = shift; |
88
|
7
|
50
|
|
|
|
23
|
my $self = ref $inv ? $inv : $inv->new(@_); |
89
|
7
|
|
|
|
|
18
|
$self->{prep_select_fields} = [ 'COUNT(*)' ]; |
90
|
7
|
100
|
|
|
|
9
|
if (@{ $self->{prep_group_by} || [] }) { |
|
7
|
100
|
|
|
|
36
|
|
91
|
2
|
|
|
|
|
6
|
my $table_name = $self->{class}->_get_table_name; |
92
|
2
|
|
|
|
|
4
|
push @{ $self->{prep_select_fields} }, map qq/"$table_name".$_/, @{ $self->{prep_group_by} }; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
7
|
|
93
|
2
|
|
|
|
|
3
|
my @group_by = @{ $self->{prep_group_by} }; |
|
2
|
|
|
|
|
4
|
|
94
|
2
|
|
|
|
|
9
|
s/"//g foreach @group_by; |
95
|
2
|
|
|
|
|
4
|
my @results; |
96
|
2
|
|
|
|
|
4
|
foreach my $item ($self->fetch) { |
97
|
7
|
|
|
|
|
13
|
push my @line, (count => $item->{'COUNT(*)'}), map {$_ => $item->$_} @group_by; |
|
7
|
|
|
|
|
15
|
|
98
|
7
|
|
|
|
|
21
|
push @results, { @line }; |
99
|
|
|
|
|
|
|
} |
100
|
2
|
|
|
|
|
12
|
return @results; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
5
|
|
|
|
|
14
|
return $self->fetch->{'COUNT(*)'}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub parse_hash { |
108
|
26
|
|
|
26
|
0
|
49
|
my ($self, $param_hash) = @_; |
109
|
26
|
|
|
|
|
42
|
my $class = $self->{class}; |
110
|
26
|
50
|
|
|
|
93
|
my $table_name = ($self->{class}->can('_get_table_name')) ? $self->{class}->_get_table_name : undef; |
111
|
26
|
|
|
|
|
58
|
my ($bind, $condition_pairs) = ([],[]); |
112
|
26
|
|
|
|
|
37
|
for my $param_name (keys %{ $param_hash }) { |
|
26
|
|
|
|
|
75
|
|
113
|
28
|
50
|
33
|
|
|
97
|
if (ref $param_hash->{$param_name} eq 'ARRAY' and !ref $param_hash->{$param_name}[0]) { |
|
|
100
|
|
|
|
|
|
114
|
0
|
|
|
|
|
0
|
my $instr = join q/, /, map { '?' } @{ $param_hash->{$param_name} }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
115
|
0
|
|
|
|
|
0
|
push @$condition_pairs, qq/"$table_name"."$param_name" IN ($instr)/; |
116
|
0
|
|
|
|
|
0
|
push @$bind, @{ $param_hash->{$param_name} }; |
|
0
|
|
|
|
|
0
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
elsif (ref $param_hash->{$param_name}) { |
119
|
2
|
50
|
|
|
|
7
|
next if !$class->can('_get_relations'); |
120
|
2
|
50
|
|
|
|
6
|
my $relation = $class->_get_relations->{$param_name} or next; |
121
|
|
|
|
|
|
|
|
122
|
2
|
50
|
|
|
|
4
|
next if $relation->{type} ne 'one'; |
123
|
2
|
|
|
|
|
3
|
my $fk = $relation->{params}{fk}; |
124
|
2
|
|
|
|
|
3
|
my $pk = $relation->{params}{pk}; |
125
|
|
|
|
|
|
|
|
126
|
2
|
50
|
|
|
|
5
|
if (ref $param_hash->{$param_name} eq __PACKAGE__) { |
127
|
0
|
|
|
|
|
0
|
my $object = $param_hash->{$param_name}; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
my $tmp_table = qq/tmp_table_/ . sprintf("%x", $object); |
130
|
0
|
|
|
|
|
0
|
my $request_table = $object->{class}->_get_table_name; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
$object->{prep_select_fields} = [qq/"$request_table"."$pk"/]; |
133
|
0
|
|
|
|
|
0
|
$object->_finish_sql_stmt; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
push @$condition_pairs, qq/"$table_name"."$fk" IN (SELECT "$tmp_table"."$pk" from ($object->{SQL}) as $tmp_table)/; |
136
|
0
|
0
|
|
|
|
0
|
push @$bind, @{ $object->{BIND} } if ref $object->{BIND} eq 'ARRAY'; |
|
0
|
|
|
|
|
0
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
2
|
|
|
|
|
3
|
my $object = $param_hash->{$param_name}; |
140
|
|
|
|
|
|
|
|
141
|
2
|
50
|
|
|
|
5
|
if (ref $object eq 'ARRAY') { |
142
|
0
|
|
|
|
|
0
|
push @$bind, map $_->$pk, @$object; |
143
|
0
|
|
|
|
|
0
|
push @$condition_pairs, qq/"$table_name"."$fk" IN (@{[ join ', ', map "?", @$object ]})/; |
|
0
|
|
|
|
|
0
|
|
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
else { |
146
|
2
|
|
|
|
|
6
|
push @$condition_pairs, qq/"$table_name"."$fk" = ?/; |
147
|
2
|
|
|
|
|
5
|
push @$bind, $object->$pk; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
else { |
152
|
26
|
50
|
|
|
|
55
|
if (defined $param_hash->{$param_name}) { |
153
|
26
|
|
|
|
|
71
|
push @$condition_pairs, qq/"$table_name"."$param_name" = ?/; |
154
|
26
|
|
|
|
|
56
|
push @$bind, $param_hash->{$param_name}; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
else { |
157
|
|
|
|
|
|
|
# is NULL |
158
|
0
|
|
|
|
|
0
|
push @$condition_pairs, qq/"$table_name"."$param_name" IS NULL/; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
26
|
|
|
|
|
60
|
return ($bind, $condition_pairs); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub first { |
166
|
6
|
|
|
6
|
1
|
12
|
my ($self, $limit) = @_; |
167
|
|
|
|
|
|
|
|
168
|
6
|
|
100
|
|
|
20
|
$limit //= 1; |
169
|
|
|
|
|
|
|
|
170
|
6
|
50
|
|
|
|
19
|
$self->{class}->can('_get_primary_key') or croak 'Can\'t use "first" without primary key'; |
171
|
6
|
|
|
|
|
16
|
my $primary_key = $self->{class}->_get_primary_key; |
172
|
|
|
|
|
|
|
|
173
|
6
|
|
|
|
|
13
|
return $self->order_by($primary_key)->limit($limit)->fetch; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub last { |
177
|
3
|
|
|
3
|
1
|
6
|
my ($self, $limit) = @_; |
178
|
|
|
|
|
|
|
|
179
|
3
|
50
|
|
|
|
13
|
$self->{class}->can('_get_primary_key') or croak 'Can\'t use "first" without primary key'; |
180
|
3
|
|
|
|
|
8
|
my $primary_key = $self->{class}->_get_primary_key; |
181
|
3
|
|
50
|
|
|
13
|
$limit //= 1; |
182
|
|
|
|
|
|
|
|
183
|
3
|
|
|
|
|
8
|
return $self->order_by($primary_key)->desc->limit($limit)->fetch; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub only { |
187
|
8
|
|
|
8
|
1
|
17
|
my ($self, @fields) = @_; |
188
|
|
|
|
|
|
|
|
189
|
8
|
50
|
|
|
|
19
|
scalar @fields > 0 or croak 'Not defined fields for method "only"'; |
190
|
8
|
50
|
|
|
|
16
|
ref $self or croak 'Create an object abstraction before using the modifiers. Use methods like `find`, `first`, `last` at the beginning'; |
191
|
|
|
|
|
|
|
|
192
|
8
|
50
|
|
|
|
26
|
if ($self->{class}->can('_get_primary_key')) { |
193
|
8
|
|
|
|
|
18
|
my $pk = $self->{class}->_get_primary_key; |
194
|
8
|
100
|
|
|
|
12
|
push @fields, $pk if ! grep { $_ eq $pk } @fields; |
|
10
|
|
|
|
|
30
|
|
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
8
|
|
|
|
|
21
|
my $table_name = $self->{class}->_get_table_name; |
198
|
8
|
100
|
|
|
|
27
|
my $mixins = $self->{class}->can('_get_mixins') ? $self->{class}->_get_mixins : undef; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
my @filtered_prep_select_fields = |
201
|
8
|
|
|
|
|
12
|
grep { $_ ne qq/"$table_name".*/ } @{ $self->{prep_select_fields} }; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
14
|
|
202
|
8
|
|
|
|
|
15
|
for my $fld (@fields) { |
203
|
11
|
100
|
100
|
|
|
27
|
if ($mixins && grep { $_ eq $fld } keys %$mixins) { |
|
9
|
|
|
|
|
27
|
|
204
|
1
|
|
|
|
|
3
|
my $mixin = $mixins->{$fld}->(); |
205
|
1
|
50
|
|
|
|
7
|
$mixin .= qq/ AS $fld/ unless $mixin =~ /as\s+\w+$/i; |
206
|
1
|
|
|
|
|
2
|
push @filtered_prep_select_fields, $mixin; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
else { |
209
|
10
|
|
|
|
|
27
|
push @filtered_prep_select_fields, qq/"$table_name"."$fld"/; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
8
|
|
|
|
|
16
|
$self->{prep_select_fields} = \@filtered_prep_select_fields; |
214
|
|
|
|
|
|
|
|
215
|
8
|
|
|
|
|
25
|
return $self; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# alias to only: |
219
|
1
|
|
|
1
|
1
|
4
|
sub fields { shift->only(@_) } |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub order_by { |
222
|
23
|
|
|
23
|
1
|
41
|
my ($self, @param) = @_; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
#return if not defined $self->{SQL}; ### TODO: die |
225
|
23
|
|
100
|
|
|
89
|
$self->{prep_order_by} ||= []; |
226
|
23
|
|
|
|
|
40
|
push @{$self->{prep_order_by}}, map qq/"$_"/, @param; |
|
23
|
|
|
|
|
82
|
|
227
|
23
|
|
|
|
|
39
|
delete $self->{prep_asc_desc}; |
228
|
|
|
|
|
|
|
|
229
|
23
|
|
|
|
|
53
|
return $self; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub desc { |
233
|
11
|
|
|
11
|
1
|
21
|
return shift->order_by_direction('DESC'); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub asc { |
237
|
2
|
|
|
2
|
1
|
22
|
return shift->order_by_direction('ASC'); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub order_by_direction { |
241
|
13
|
|
|
13
|
0
|
22
|
my ($self, $direction) = @_; |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# There are no fields for order yet |
244
|
13
|
50
|
33
|
|
|
32
|
return unless ref $self->{prep_order_by} eq 'ARRAY' and scalar @{ $self->{prep_order_by} } > 0; |
|
13
|
|
|
|
|
37
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
# asc/desc is called before: ->asc->desc |
247
|
13
|
50
|
|
|
|
27
|
return if defined $self->{prep_asc_desc}; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
# $direction should be ASC/DESC |
250
|
13
|
50
|
|
|
|
64
|
return unless $direction =~ /^(ASC|DESC)$/i; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# Add $direction to the latest field |
253
|
13
|
|
|
|
|
17
|
@{$self->{prep_order_by}}[-1] .= " $direction"; |
|
13
|
|
|
|
|
32
|
|
254
|
13
|
|
|
|
|
21
|
$self->{prep_asc_desc} = 1; |
255
|
|
|
|
|
|
|
|
256
|
13
|
|
|
|
|
34
|
return $self; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub group_by { |
260
|
3
|
|
|
3
|
1
|
7
|
my ($self, @param) = @_; |
261
|
|
|
|
|
|
|
|
262
|
3
|
|
50
|
|
|
13
|
$self->{prep_group_by} ||= []; |
263
|
3
|
|
|
|
|
3
|
push @{$self->{prep_group_by}}, map qq/"$_"/, @param; |
|
3
|
|
|
|
|
12
|
|
264
|
3
|
|
|
|
|
10
|
return $self; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub limit { |
268
|
14
|
|
|
14
|
1
|
24
|
my ($self, $limit) = @_; |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
#return if not defined $self->{SQL}; |
271
|
14
|
50
|
|
|
|
28
|
return $self if exists $self->{prep_limit}; |
272
|
|
|
|
|
|
|
|
273
|
14
|
|
|
|
|
24
|
$self->{prep_limit} = $limit; ### TODO: move $limit to $self->{BIND} |
274
|
|
|
|
|
|
|
|
275
|
14
|
|
|
|
|
29
|
return $self; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub offset { |
279
|
5
|
|
|
5
|
1
|
9
|
my ($self, $offset) = @_; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
#return if not defined $self->{SQL}; |
282
|
5
|
50
|
|
|
|
12
|
return $self if exists $self->{prep_offset}; |
283
|
|
|
|
|
|
|
|
284
|
5
|
|
|
|
|
8
|
$self->{prep_offset} = $offset; ### TODO: move $offset to $self->{BIND} |
285
|
|
|
|
|
|
|
|
286
|
5
|
|
|
|
|
12
|
return $self; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
sub abstract { |
290
|
7
|
|
|
7
|
0
|
11
|
my ($self, $opts) = @_; |
291
|
|
|
|
|
|
|
|
292
|
7
|
100
|
66
|
|
|
22
|
return $self if ! ref $opts && ref $opts ne 'HASH'; |
293
|
|
|
|
|
|
|
|
294
|
5
|
|
|
|
|
17
|
while (my ($method, $param) = each %$opts) { |
295
|
9
|
100
|
|
|
|
15
|
if ($method eq 'order_by') { |
296
|
4
|
|
|
|
|
6
|
$self->order_by(@{ $param->{columns} }); |
|
4
|
|
|
|
|
9
|
|
297
|
4
|
50
|
|
|
|
9
|
my $order_direction = (defined $param->{direction}) ? $param->{direction} : undef; |
298
|
4
|
50
|
|
|
|
10
|
$self->$order_direction if $order_direction; |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
else { |
301
|
5
|
100
|
|
|
|
10
|
my @p = (ref $param) ? @$param : ($param); |
302
|
5
|
|
|
|
|
11
|
$self->$method(@p); |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
5
|
|
|
|
|
8
|
return $self; |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub select { |
310
|
6
|
|
|
6
|
1
|
14
|
my ($self_class, $class, @params) = @_; |
311
|
|
|
|
|
|
|
|
312
|
6
|
|
|
|
|
9
|
my @find_params; |
313
|
|
|
|
|
|
|
my $abstract_params_hashref; |
314
|
|
|
|
|
|
|
|
315
|
6
|
|
|
|
|
8
|
my $first_param = shift @params; |
316
|
6
|
100
|
|
|
|
17
|
push @find_params, $first_param if defined $first_param; |
317
|
|
|
|
|
|
|
|
318
|
6
|
|
|
|
|
9
|
for my $param (@params) { |
319
|
|
|
|
|
|
|
#push @find_params, $param if ref $param ne 'HASH'; |
320
|
5
|
100
|
|
|
|
13
|
if (ref $param eq 'HASH') { |
321
|
4
|
|
|
|
|
5
|
$abstract_params_hashref = $param; |
322
|
4
|
|
|
|
|
6
|
last; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
else { |
325
|
1
|
|
|
|
|
2
|
push @find_params, $param; |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
6
|
|
|
|
|
13
|
my $finder = $self_class->new($class, @find_params); |
330
|
6
|
|
|
|
|
12
|
$finder->abstract($abstract_params_hashref); |
331
|
|
|
|
|
|
|
|
332
|
6
|
|
|
|
|
12
|
return $finder->fetch; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
sub _finish_sql_stmt { |
337
|
82
|
|
|
82
|
|
119
|
my ($self) = @_; |
338
|
|
|
|
|
|
|
|
339
|
82
|
50
|
|
|
|
171
|
ref $self->{prep_select_fields} or croak 'Invalid prepare SQL statement'; |
340
|
82
|
50
|
|
|
|
146
|
ref $self->{prep_select_from} or croak 'Invalid prepare SQL statement'; |
341
|
|
|
|
|
|
|
|
342
|
82
|
|
|
|
|
179
|
my $table_name = $self->{class}->_get_table_name; |
343
|
82
|
100
|
|
|
|
117
|
my @add = grep { $_ !~~ $self->{prep_select_fields} } map qq/"$table_name".$_/, @{ $self->{prep_group_by}||[] }; |
|
4
|
|
|
|
|
48
|
|
|
82
|
|
|
|
|
266
|
|
344
|
82
|
|
|
|
|
110
|
push @{ $self->{prep_select_fields} }, @add; |
|
82
|
|
|
|
|
137
|
|
345
|
|
|
|
|
|
|
|
346
|
82
|
|
|
|
|
106
|
$self->{SQL} = "SELECT " . (join q/, /, @{ $self->{prep_select_fields} }) . "\n"; |
|
82
|
|
|
|
|
246
|
|
347
|
82
|
|
|
|
|
133
|
$self->{SQL} .= "FROM " . (join q/, /, @{ $self->{prep_select_from} }) . "\n"; |
|
82
|
|
|
|
|
210
|
|
348
|
|
|
|
|
|
|
|
349
|
82
|
100
|
|
|
|
163
|
if (defined $self->{prep_left_joins}) { |
350
|
7
|
|
|
|
|
11
|
$self->{SQL} .= "$_\n" for @{ $self->{prep_left_joins} }; |
|
7
|
|
|
|
|
25
|
|
351
|
7
|
|
|
|
|
17
|
$self->{has_joined_table} = 1; |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
|
354
|
82
|
50
|
|
|
|
100
|
if (@{ $self->{prep_select_where}||[] }) { |
|
82
|
100
|
|
|
|
209
|
|
355
|
52
|
|
|
|
|
77
|
$self->{SQL} .= "WHERE\n"; |
356
|
52
|
|
|
|
|
69
|
$self->{SQL} .= join " AND ", @{ $self->{prep_select_where} }; |
|
52
|
|
|
|
|
102
|
|
357
|
|
|
|
|
|
|
} |
358
|
|
|
|
|
|
|
|
359
|
82
|
100
|
|
|
|
107
|
if (@{ $self->{prep_group_by}||[] }) { |
|
82
|
100
|
|
|
|
245
|
|
360
|
3
|
|
|
|
|
5
|
$self->{SQL} .= ' GROUP BY '; |
361
|
3
|
|
|
|
|
6
|
$self->{SQL} .= join q/, /, @{ $self->{prep_group_by} }; |
|
3
|
|
|
|
|
5
|
|
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
|
364
|
82
|
100
|
|
|
|
119
|
if (@{ $self->{prep_order_by}||[] }) { |
|
82
|
100
|
|
|
|
228
|
|
365
|
24
|
|
|
|
|
38
|
$self->{SQL} .= ' ORDER BY '; |
366
|
24
|
|
|
|
|
32
|
$self->{SQL} .= join q/, /, @{ $self->{prep_order_by} }; |
|
24
|
|
|
|
|
35
|
|
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
|
369
|
82
|
|
66
|
|
|
268
|
$self->{SQL} .= ' LIMIT ' . ($self->{prep_limit} // $MAXIMUM_LIMIT); |
370
|
82
|
|
100
|
|
|
239
|
$self->{SQL} .= ' OFFSET '. ($self->{prep_offset} // 0); |
371
|
|
|
|
|
|
|
|
372
|
82
|
|
|
|
|
123
|
return $self; |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
sub _finish_object_representation { |
376
|
130
|
|
|
130
|
|
222
|
my ($self, $obj, $object_data, $read_only) = @_; |
377
|
|
|
|
|
|
|
|
378
|
130
|
100
|
|
|
|
256
|
if ($self->{has_joined_table}) { |
379
|
|
|
|
|
|
|
RELATION: |
380
|
14
|
|
|
|
|
19
|
for my $rel_name (@{ $self->{with} }) { |
|
14
|
|
|
|
|
32
|
|
381
|
0
|
0
|
|
|
|
0
|
my $relation = $self->{class}->_get_relations->{$rel_name} or next RELATION; |
382
|
0
|
|
|
|
|
0
|
my %pairs = map { $_, $object_data->{$_} } grep { $_ =~ /^JOINED\_$rel_name\_/ } keys %$object_data; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
383
|
0
|
0
|
|
|
|
0
|
next RELATION unless %pairs; |
384
|
|
|
|
|
|
|
|
385
|
0
|
|
|
|
|
0
|
for my $key (keys %pairs) { |
386
|
0
|
|
|
|
|
0
|
my $val = delete $pairs{$key}; |
387
|
0
|
|
|
|
|
0
|
$key =~ s/^JOINED\_$rel_name\_//; |
388
|
0
|
|
|
|
|
0
|
$pairs{$key} = $val; |
389
|
|
|
|
|
|
|
} |
390
|
0
|
|
|
|
|
0
|
$obj->{"relation_instance_$rel_name"} = $relation->{class}->new(\%pairs); |
391
|
|
|
|
|
|
|
|
392
|
0
|
|
|
|
|
0
|
$obj->_delete_keys(qr/^JOINED\_$rel_name/); |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
|
397
|
130
|
50
|
|
|
|
204
|
$obj->{read_only} = 1 if defined $read_only; |
398
|
130
|
100
|
66
|
|
|
449
|
$obj->{snapshoot} = freeze($object_data) if $obj->can('_smart_saving_used') && $obj->_smart_saving_used; |
399
|
130
|
|
|
|
|
312
|
$obj->{isin_database} = 1; |
400
|
|
|
|
|
|
|
|
401
|
130
|
|
|
|
|
191
|
return $obj; |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
sub fetch { |
405
|
76
|
|
|
76
|
1
|
139
|
my ($self, $param) = @_; |
406
|
|
|
|
|
|
|
|
407
|
76
|
|
|
|
|
105
|
my ($read_only, $limit); |
408
|
76
|
50
|
|
|
|
164
|
if (ref $param eq 'HASH') { |
409
|
0
|
|
|
|
|
0
|
$limit = $param->{limit}; |
410
|
0
|
|
|
|
|
0
|
$read_only = $param->{read_only}; |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
else { |
413
|
76
|
|
|
|
|
105
|
$limit = $param; |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
|
416
|
76
|
50
|
|
|
|
138
|
return $self->_get_slice($limit) if $self->{_objects}; |
417
|
|
|
|
|
|
|
|
418
|
76
|
|
|
|
|
170
|
$self->_finish_sql_stmt(); |
419
|
76
|
|
|
|
|
179
|
$self->_quote_sql_stmt(); |
420
|
|
|
|
|
|
|
|
421
|
76
|
|
|
|
|
110
|
my $class = $self->{class}; |
422
|
76
|
50
|
|
|
|
144
|
my $sth = $self->dbh->prepare($self->{SQL}) or croak $self->dbh->errstr; |
423
|
|
|
|
|
|
|
|
424
|
76
|
50
|
|
|
|
4549
|
$sth->execute(@{ $self->{BIND} }) or croak $self->dbh->errstr; |
|
76
|
|
|
|
|
1770
|
|
425
|
76
|
100
|
|
|
|
232
|
if (wantarray) { |
426
|
29
|
|
|
|
|
40
|
my @objects; |
427
|
29
|
|
|
|
|
45
|
my $i = 0; |
428
|
29
|
|
|
|
|
542
|
while (my $object_data = $sth->fetchrow_hashref()) { |
429
|
83
|
|
|
|
|
135
|
$i++; |
430
|
83
|
|
|
|
|
206
|
my $obj = $class->new($object_data); |
431
|
83
|
|
|
|
|
196
|
$self->_finish_object_representation($obj, $object_data, $read_only); |
432
|
83
|
|
|
|
|
113
|
push @objects, $obj; |
433
|
|
|
|
|
|
|
|
434
|
83
|
50
|
33
|
|
|
1195
|
last if $limit && $i == $limit; |
435
|
|
|
|
|
|
|
} |
436
|
29
|
|
|
|
|
105
|
delete $self->{has_joined_table}; |
437
|
|
|
|
|
|
|
|
438
|
29
|
|
|
|
|
384
|
return @objects; |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
else { |
441
|
47
|
50
|
|
|
|
638
|
my $object_data = $sth->fetchrow_hashref() or return; |
442
|
47
|
|
|
|
|
227
|
my $obj = $class->new($object_data); |
443
|
47
|
|
|
|
|
125
|
$self->_finish_object_representation($obj, $object_data, $read_only); |
444
|
47
|
|
|
|
|
62
|
delete $self->{has_joined_table}; |
445
|
|
|
|
|
|
|
|
446
|
47
|
|
|
|
|
616
|
return $obj; |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
sub upload { |
451
|
1
|
|
|
1
|
1
|
5
|
my ($self, $param) = @_; |
452
|
|
|
|
|
|
|
|
453
|
1
|
|
|
|
|
12
|
my $o = $self->fetch($param); |
454
|
1
|
|
|
|
|
3
|
$_[0] = $o; |
455
|
|
|
|
|
|
|
|
456
|
1
|
|
|
|
|
5
|
return $_[0]; |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
sub next { |
460
|
7
|
|
|
7
|
0
|
1801
|
my ($self, $n) = @_; |
461
|
|
|
|
|
|
|
|
462
|
7
|
|
100
|
|
|
20
|
$n ||= 1; |
463
|
|
|
|
|
|
|
|
464
|
7
|
|
|
|
|
13
|
$self->{prep_limit} = $n; |
465
|
7
|
100
|
|
|
|
20
|
$self->{prep_offset} = 0 unless defined $self->{prep_offset}; |
466
|
7
|
|
|
|
|
11
|
my @result = $self->fetch; |
467
|
|
|
|
|
|
|
|
468
|
7
|
|
|
|
|
15
|
$self->{prep_offset} += $n; |
469
|
|
|
|
|
|
|
|
470
|
7
|
100
|
|
|
|
23
|
return wantarray ? @result : $result[0]; |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
sub with { |
474
|
0
|
|
|
0
|
1
|
0
|
my ($self, @rels) = @_; |
475
|
|
|
|
|
|
|
|
476
|
0
|
0
|
|
|
|
0
|
return $self if exists $self->{prep_left_joins}; |
477
|
0
|
0
|
|
|
|
0
|
return $self unless @rels; |
478
|
|
|
|
|
|
|
|
479
|
0
|
0
|
|
|
|
0
|
$self->{class}->can('_get_relations') |
480
|
|
|
|
|
|
|
or die "Class doesn't have any relations"; |
481
|
|
|
|
|
|
|
|
482
|
0
|
|
|
|
|
0
|
my $table_name = $self->{class}->_get_table_name; |
483
|
|
|
|
|
|
|
|
484
|
0
|
|
|
|
|
0
|
$self->{prep_left_joins} = []; |
485
|
0
|
|
|
|
|
0
|
$self->{with} = \@rels; |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
RELATION: |
488
|
0
|
|
|
|
|
0
|
for my $rel_name (@rels) { |
489
|
0
|
0
|
|
|
|
0
|
my $relation = $self->{class}->_get_relations->{$rel_name} |
490
|
|
|
|
|
|
|
or next RELATION; |
491
|
|
|
|
|
|
|
|
492
|
0
|
0
|
|
|
|
0
|
next RELATION unless grep { $_ eq $relation->{type} } qw/one only/; |
|
0
|
|
|
|
|
0
|
|
493
|
0
|
|
|
|
|
0
|
my $rel_table_name = $relation->{class}->_get_table_name; |
494
|
0
|
|
|
|
|
0
|
my $rel_columns = $relation->{class}->_get_columns; |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
REL_COLUMN: |
497
|
0
|
|
|
|
|
0
|
for (@$rel_columns) { |
498
|
0
|
0
|
|
|
|
0
|
next REL_COLUMN if ref $_; |
499
|
0
|
|
|
|
|
0
|
push @{ $self->{prep_select_fields} }, qq/"$rel_table_name"."$_" AS "JOINED_$rel_name\_$_"/; |
|
0
|
|
|
|
|
0
|
|
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
|
502
|
0
|
0
|
|
|
|
0
|
if ($relation->{type} eq 'one') { |
503
|
0
|
|
|
|
|
0
|
my $join_sql = qq/LEFT JOIN "$rel_table_name" ON /; |
504
|
0
|
|
|
|
|
0
|
$join_sql .= qq/"$rel_table_name"."$relation->{params}{pk}"/; |
505
|
0
|
|
|
|
|
0
|
$join_sql .= qq/ = "$table_name"."$relation->{params}{fk}"/; |
506
|
|
|
|
|
|
|
|
507
|
0
|
|
|
|
|
0
|
push @{ $self->{prep_left_joins} }, $join_sql; |
|
0
|
|
|
|
|
0
|
|
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
0
|
|
|
|
|
0
|
return $self; |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
0
|
|
|
0
|
1
|
0
|
sub left_join { shift->with(@_) } |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
sub to_sql { |
517
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
518
|
|
|
|
|
|
|
|
519
|
0
|
|
|
|
|
0
|
$self->_finish_sql_stmt(); |
520
|
0
|
|
|
|
|
0
|
$self->_quote_sql_stmt(); |
521
|
|
|
|
|
|
|
|
522
|
0
|
0
|
|
|
|
0
|
return wantarray ? ($self->{SQL}, $self->{BIND}) : $self->{SQL}; |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
sub exists { |
526
|
6
|
|
|
6
|
1
|
10
|
my ($self) = @_; |
527
|
|
|
|
|
|
|
|
528
|
6
|
|
|
|
|
15
|
$self->{prep_select_fields} = ['1']; |
529
|
6
|
|
|
|
|
16
|
$self->_finish_sql_stmt; |
530
|
6
|
|
|
|
|
32
|
$self->_quote_sql_stmt; |
531
|
|
|
|
|
|
|
|
532
|
6
|
|
|
|
|
33
|
my $sth = $self->dbh->prepare($self->{SQL}); |
533
|
6
|
|
|
|
|
382
|
$sth->execute(@{ $self->{BIND} }); |
|
6
|
|
|
|
|
101
|
|
534
|
|
|
|
|
|
|
|
535
|
6
|
|
|
|
|
104
|
return $sth->fetchrow_arrayref(); |
536
|
|
|
|
|
|
|
} |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
### Private |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
sub _find_many_to_many { |
542
|
7
|
|
|
7
|
|
14
|
my ($self_class, $class, $param) = @_; |
543
|
|
|
|
|
|
|
|
544
|
7
|
50
|
33
|
|
|
18
|
return unless $self_class->dbh && $class && $param; |
|
|
|
33
|
|
|
|
|
545
|
|
|
|
|
|
|
|
546
|
7
|
|
|
|
|
11
|
my $mc_fkey; |
547
|
7
|
|
|
|
|
12
|
my $class_opts = {}; |
548
|
7
|
|
|
|
|
9
|
my $root_class_opts = {}; |
549
|
|
|
|
|
|
|
|
550
|
7
|
|
|
|
|
12
|
eval { load $param->{m_class} }; |
|
7
|
|
|
|
|
19
|
|
551
|
|
|
|
|
|
|
|
552
|
7
|
|
|
|
|
1072
|
for my $opts ( values %{ $param->{m_class}->_get_relations } ) { |
|
7
|
|
|
|
|
25
|
|
553
|
14
|
100
|
|
|
|
41
|
if ($opts->{class} eq $param->{root_class}) { |
|
|
50
|
|
|
|
|
|
554
|
7
|
|
|
|
|
14
|
$root_class_opts = $opts; |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
elsif ($opts->{class} eq $class) { |
557
|
7
|
|
|
|
|
15
|
$class_opts = $opts; |
558
|
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
7
|
|
|
|
|
15
|
my $self = $self_class->new($class, @{ $param->{where_statement} }); |
|
7
|
|
|
|
|
23
|
|
562
|
|
|
|
|
|
|
|
563
|
7
|
|
|
|
|
16
|
my $connected_table_name = $class->_get_table_name; |
564
|
7
|
|
|
|
|
18
|
$self->{prep_select_from} = [ $param->{m_class}->_get_table_name ]; |
565
|
|
|
|
|
|
|
|
566
|
7
|
|
|
|
|
62
|
push @{ $self->{prep_left_joins} }, |
567
|
|
|
|
|
|
|
'JOIN ' . $connected_table_name . ' ON ' . $connected_table_name . '.' . $class->_get_primary_key . ' = ' |
568
|
7
|
|
|
|
|
10
|
. $param->{m_class}->_get_table_name . '.' . $class_opts->{params}{fk}; |
569
|
|
|
|
|
|
|
|
570
|
7
|
|
|
|
|
25
|
push @{ $self->{prep_select_where} }, |
571
|
7
|
|
|
|
|
14
|
$root_class_opts->{params}{fk} . ' = ' . $param->{self}->{ $param->{root_class}->_get_primary_key }; |
572
|
|
|
|
|
|
|
|
573
|
7
|
|
|
|
|
39
|
return $self; |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
sub _get_slice { |
577
|
0
|
|
|
0
|
|
0
|
my ($self, $time) = @_; |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
return unless $self->{_objects} |
580
|
|
|
|
|
|
|
&& ref $self->{_objects} eq 'ARRAY' |
581
|
0
|
0
|
0
|
|
|
0
|
&& scalar @{ $self->{_objects} } > 0; |
|
0
|
|
0
|
|
|
0
|
|
582
|
|
|
|
|
|
|
|
583
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
584
|
0
|
|
0
|
|
|
0
|
$time ||= scalar @{ $self->{_objects} }; |
|
0
|
|
|
|
|
0
|
|
585
|
0
|
|
|
|
|
0
|
return splice @{ $self->{_objects} }, 0, $time; |
|
0
|
|
|
|
|
0
|
|
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
else { |
588
|
0
|
|
|
|
|
0
|
return shift @{ $self->{_objects} }; |
|
0
|
|
|
|
|
0
|
|
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
} |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
sub _quote_sql_stmt { |
593
|
82
|
|
|
82
|
|
131
|
my ($self) = @_; |
594
|
|
|
|
|
|
|
|
595
|
82
|
50
|
33
|
|
|
249
|
return unless $self->{SQL} && $self->dbh; |
596
|
|
|
|
|
|
|
|
597
|
82
|
|
|
|
|
231
|
my $driver_name = $self->dbh->{Driver}{Name}; |
598
|
82
|
|
50
|
|
|
262
|
$driver_name //= 'Pg'; |
599
|
82
|
|
|
|
|
244
|
my $quotes_map = { |
600
|
|
|
|
|
|
|
Pg => q/"/, |
601
|
|
|
|
|
|
|
mysql => q/`/, |
602
|
|
|
|
|
|
|
SQLite => q/`/, |
603
|
|
|
|
|
|
|
}; |
604
|
82
|
|
|
|
|
140
|
my $quote = $quotes_map->{$driver_name}; |
605
|
|
|
|
|
|
|
|
606
|
82
|
|
|
|
|
427
|
$self->{SQL} =~ s/"/$quote/g; |
607
|
|
|
|
|
|
|
|
608
|
82
|
|
|
|
|
212
|
return $self; |
609
|
|
|
|
|
|
|
} |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
0
|
|
|
sub DESTROY { } |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
sub AUTOLOAD { |
614
|
0
|
|
|
0
|
|
|
my $call = $AUTOLOAD; |
615
|
0
|
|
|
|
|
|
my $self = shift; |
616
|
0
|
|
|
|
|
|
my $class = ref $self; |
617
|
|
|
|
|
|
|
|
618
|
0
|
|
|
|
|
|
$call =~ s/.*:://; |
619
|
0
|
|
|
|
|
|
my $error = "Can't call method `$call` on class $class.\nPerhaps you have forgotten to fetch your object?"; |
620
|
|
|
|
|
|
|
|
621
|
0
|
|
|
|
|
|
croak $error; |
622
|
|
|
|
|
|
|
} |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
1; |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
|