line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EntityModel::Query::Update; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$EntityModel::Query::Update::VERSION = '0.102'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
use EntityModel::Class { |
6
|
16
|
|
|
|
|
157
|
_isa => [qw{EntityModel::Query}], |
7
|
|
|
|
|
|
|
'set' => { type => 'array', subclass => 'EntityModel::Query::Field' }, |
8
|
16
|
|
|
16
|
|
82
|
}; |
|
16
|
|
|
|
|
33
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
EntityModel::Query::Update - update statement |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
version 0.102 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
See L. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
See L. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 import |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Register the parse handling for our 'insert' attribute. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub import { |
39
|
16
|
|
|
16
|
|
34
|
my $class = shift; |
40
|
|
|
|
|
|
|
$class->register( |
41
|
|
|
|
|
|
|
'update' => sub { |
42
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
43
|
1
|
|
|
|
|
7
|
$self->upgradeTo('EntityModel::Query::Update'); |
44
|
1
|
|
|
|
|
9
|
$self->parse_base( |
45
|
|
|
|
|
|
|
@_, |
46
|
|
|
|
|
|
|
method => 'from', |
47
|
|
|
|
|
|
|
type => 'EntityModel::Query::FromTable' |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
16
|
|
|
|
|
156
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 type |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
1
|
1
|
4
|
sub type { 'update'; } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 parse_fields |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Populate the values for the update statement. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub parse_fields { |
66
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
67
|
1
|
|
|
|
|
2
|
my $spec = shift; |
68
|
1
|
50
|
|
|
|
9
|
my @entries = ref $spec eq 'HASH' ? %$spec : @$spec; |
69
|
1
|
|
|
|
|
5
|
while(@entries) { |
70
|
2
|
|
|
|
|
4
|
my $k = shift(@entries); |
71
|
2
|
|
|
|
|
4
|
my $v = shift(@entries); |
72
|
2
|
|
|
|
|
21
|
$self->parse_base({ |
73
|
|
|
|
|
|
|
name => $k, |
74
|
|
|
|
|
|
|
value => $v, |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
method => 'set', |
77
|
|
|
|
|
|
|
type => 'EntityModel::Query::UpdateField' |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 keyword_order |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
1
|
0
|
sub keyword_order { qw{type from join fields where order offset limit}; } |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 fromSQL |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub fromSQL { |
93
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
94
|
0
|
|
|
|
|
0
|
my $from = join(', ', map { $_->asString } $self->from->list); |
|
0
|
|
|
|
|
0
|
|
95
|
0
|
0
|
|
|
|
0
|
return unless $from; |
96
|
0
|
|
|
|
|
0
|
return $from; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 fieldsSQL |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub fieldsSQL { |
104
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
105
|
0
|
|
|
|
|
0
|
my $fields = join(', ', map { |
106
|
0
|
|
|
|
|
0
|
$_->asString . ' = ' . $_->quotedValue |
107
|
|
|
|
|
|
|
} $self->set->list); |
108
|
0
|
0
|
|
|
|
0
|
return unless $fields; |
109
|
0
|
|
|
|
|
0
|
return 'set ' . $fields; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub inlineSQL { |
113
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
114
|
2
|
|
|
|
|
26
|
my $data = [ |
115
|
|
|
|
|
|
|
'update ', |
116
|
2
|
|
|
|
|
7
|
(map { $_->asString } $self->from->list), |
117
|
|
|
|
|
|
|
' set ', |
118
|
|
|
|
|
|
|
]; |
119
|
2
|
|
|
|
|
3
|
my @field; |
120
|
2
|
|
|
|
|
6
|
foreach ($self->set->list) { |
121
|
4
|
|
|
|
|
26
|
my $v = $_->value; |
122
|
4
|
100
|
|
|
|
17
|
push @field, ', ' if @field; |
123
|
4
|
|
|
|
|
10
|
push @field, $_->name; |
124
|
4
|
|
|
|
|
14
|
push @field, ' = '; |
125
|
4
|
|
|
|
|
8
|
push @field, \$v; |
126
|
|
|
|
|
|
|
} |
127
|
2
|
|
|
|
|
6
|
push @$data, @field; |
128
|
2
|
50
|
|
|
|
7
|
push @$data, ' ', @{$self->whereSQL} if $self->where; |
|
2
|
|
|
|
|
16
|
|
129
|
2
|
|
|
|
|
13
|
return $data; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |