line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::SQL::Delete; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
117
|
use strict; |
|
27
|
|
|
|
|
43
|
|
|
27
|
|
|
|
|
868
|
|
4
|
27
|
|
|
27
|
|
169
|
use warnings; |
|
27
|
|
|
|
|
38
|
|
|
27
|
|
|
|
|
559
|
|
5
|
27
|
|
|
27
|
|
517
|
use namespace::autoclean; |
|
27
|
|
|
|
|
13603
|
|
|
27
|
|
|
|
|
138
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.42'; |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
2117
|
use Fey::Types qw( ArrayRef CanQuote Table ); |
|
27
|
|
|
|
|
55
|
|
|
27
|
|
|
|
|
220
|
|
10
|
27
|
|
|
27
|
|
311432
|
use Scalar::Util qw( blessed ); |
|
27
|
|
|
|
|
65
|
|
|
27
|
|
|
|
|
1878
|
|
11
|
|
|
|
|
|
|
|
12
|
27
|
|
|
27
|
|
144
|
use Moose 0.90; |
|
27
|
|
|
|
|
743
|
|
|
27
|
|
|
|
|
218
|
|
13
|
27
|
|
|
27
|
|
178358
|
use MooseX::Params::Validate 0.08 qw( pos_validated_list ); |
|
27
|
|
|
|
|
1288015
|
|
|
27
|
|
|
|
|
184
|
|
14
|
27
|
|
|
27
|
|
18768
|
use MooseX::SemiAffordanceAccessor 0.03; |
|
27
|
|
|
|
|
270089
|
|
|
27
|
|
|
|
|
172
|
|
15
|
27
|
|
|
27
|
|
188651
|
use MooseX::StrictConstructor 0.07; |
|
27
|
|
|
|
|
342317
|
|
|
27
|
|
|
|
|
161
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with 'Fey::Role::SQL::HasWhereClause', |
18
|
|
|
|
|
|
|
'Fey::Role::SQL::HasOrderByClause', |
19
|
|
|
|
|
|
|
'Fey::Role::SQL::HasLimitClause'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
with 'Fey::Role::SQL::HasBindParams' => { -excludes => 'bind_params' }; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has '_from' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => ArrayRef, |
26
|
|
|
|
|
|
|
default => sub { [] }, |
27
|
|
|
|
|
|
|
init_arg => undef, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
with 'Fey::Role::SQL::Cloneable'; |
31
|
|
|
|
|
|
|
|
32
|
6
|
|
|
6
|
1
|
43
|
sub delete { return $_[0] } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub from { |
35
|
6
|
|
|
6
|
1
|
519
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
6
|
100
|
|
|
|
14
|
my $count = @_ ? @_ : 1; |
38
|
6
|
|
|
|
|
25
|
my (@tables) = pos_validated_list( |
39
|
|
|
|
|
|
|
\@_, |
40
|
|
|
|
|
|
|
( ( { isa => Table } ) x $count ), |
41
|
|
|
|
|
|
|
MX_PARAMS_VALIDATE_NO_CACHE => 1, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
2836
|
$self->_set_from( \@tables ); |
45
|
|
|
|
|
|
|
|
46
|
5
|
|
|
|
|
15
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub sql { |
50
|
3
|
|
|
3
|
1
|
12
|
my $self = shift; |
51
|
3
|
|
|
|
|
12
|
my ($dbh) = pos_validated_list( \@_, { isa => CanQuote } ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return ( |
54
|
3
|
|
|
|
|
116
|
join ' ', |
55
|
|
|
|
|
|
|
$self->delete_clause($dbh), |
56
|
|
|
|
|
|
|
$self->where_clause($dbh), |
57
|
|
|
|
|
|
|
$self->order_by_clause($dbh), |
58
|
|
|
|
|
|
|
$self->limit_clause($dbh), |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub delete_clause { |
63
|
5
|
|
|
5
|
1
|
22
|
return 'DELETE FROM ' . $_[0]->_tables_subclause( $_[1] ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _tables_subclause { |
67
|
|
|
|
|
|
|
return ( |
68
|
6
|
|
|
|
|
176
|
join ', ', |
69
|
5
|
|
|
5
|
|
8
|
map { $_[1]->quote_identifier( $_->name() ) } @{ $_[0]->_from() } |
|
5
|
|
|
|
|
122
|
|
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# ABSTRACT: Represents a DELETE query |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=pod |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Fey::SQL::Delete - Represents a DELETE query |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 VERSION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
version 0.42 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SYNOPSIS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $sql = Fey::SQL->new_delete(); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# DELETE FROM Part |
96
|
|
|
|
|
|
|
# WHERE Part.name LIKE '%Widget' |
97
|
|
|
|
|
|
|
$sql->delete(); |
98
|
|
|
|
|
|
|
$sql->from($Part); |
99
|
|
|
|
|
|
|
$sql->where( $name, 'LIKE', '%Widget' ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
print $sql->sql($dbh); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This class represents a C<DELETE> query. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 METHODS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This class provides the following methods: |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 Constructor |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
To construct an object of this class, call C<< $query->delete() >> on |
114
|
|
|
|
|
|
|
a C<Fey::SQL> object. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 $delete->delete() |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This method is basically a no-op that exists to so that L<Fey::SQL> |
119
|
|
|
|
|
|
|
has something to call after it constructs an object in this class. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 $delete->from(...) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This method specifies the C<FROM> clause of the query. It expects one |
124
|
|
|
|
|
|
|
or more L<Fey::Table> objects (not aliases). Most RDBMS |
125
|
|
|
|
|
|
|
implementations only allow for a single table here, but some (like |
126
|
|
|
|
|
|
|
MySQL) do allow for multi-table deletes. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 $delete->where(...) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
See the L<Fey::SQL section on WHERE Clauses|Fey::SQL/WHERE Clauses> |
131
|
|
|
|
|
|
|
for more details. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 $delete->order_by(...) |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
See the L<Fey::SQL section on ORDER BY Clauses|Fey::SQL/ORDER BY |
136
|
|
|
|
|
|
|
Clauses> for more details. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 $delete->limit(...) |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
See the L<Fey::SQL section on LIMIT Clauses|Fey::SQL/LIMIT Clauses> |
141
|
|
|
|
|
|
|
for more details. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 $delete->sql() |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Returns the full SQL statement which this object represents. A DBI |
146
|
|
|
|
|
|
|
handle must be passed so that identifiers can be properly quoted. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 $delete->bind_params() |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
See the L<Fey::SQL section on Bind Parameters|Fey::SQL/Bind |
151
|
|
|
|
|
|
|
Parameters> for more details. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 $delete->delete_clause() |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns the C<DELETE> clause portion of the SQL statement as a string. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 $delete->where_clause() |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Returns the C<WHERE> clause portion of the SQL statement as a string. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 $delete->order_by_clause() |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Returns the C<ORDER BY> clause portion of the SQL statement as a |
164
|
|
|
|
|
|
|
string. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 $delete->limit_clause() |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns the C<LIMIT> clause portion of the SQL statement as a string. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 ROLES |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=over 4 |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * L<Fey::Role::SQL::HasBindParams> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * L<Fey::Role::SQL::HasWhereClause> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * L<Fey::Role::SQL::HasOrderByClause> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * L<Fey::Role::SQL::HasLimitClause> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * L<Fey::Role::SQL::Cloneable> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 BUGS |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
See L<Fey> for details on how to report bugs. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 AUTHOR |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This software is Copyright (c) 2011 - 2015 by Dave Rolsky. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This is free software, licensed under: |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |