line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::SQL::Delete; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
131
|
use strict; |
|
27
|
|
|
|
|
44
|
|
|
27
|
|
|
|
|
870
|
|
4
|
27
|
|
|
27
|
|
122
|
use warnings; |
|
27
|
|
|
|
|
42
|
|
|
27
|
|
|
|
|
602
|
|
5
|
27
|
|
|
27
|
|
626
|
use namespace::autoclean; |
|
27
|
|
|
|
|
16535
|
|
|
27
|
|
|
|
|
144
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.43'; |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
2273
|
use Fey::Types qw( ArrayRef CanQuote Table ); |
|
27
|
|
|
|
|
49
|
|
|
27
|
|
|
|
|
243
|
|
10
|
27
|
|
|
27
|
|
309558
|
use Scalar::Util qw( blessed ); |
|
27
|
|
|
|
|
63
|
|
|
27
|
|
|
|
|
2030
|
|
11
|
|
|
|
|
|
|
|
12
|
27
|
|
|
27
|
|
146
|
use Moose 2.1200; |
|
27
|
|
|
|
|
953
|
|
|
27
|
|
|
|
|
225
|
|
13
|
27
|
|
|
27
|
|
169572
|
use MooseX::Params::Validate 0.21 qw( pos_validated_list ); |
|
27
|
|
|
|
|
1365397
|
|
|
27
|
|
|
|
|
188
|
|
14
|
27
|
|
|
27
|
|
19020
|
use MooseX::SemiAffordanceAccessor 0.03; |
|
27
|
|
|
|
|
287512
|
|
|
27
|
|
|
|
|
186
|
|
15
|
27
|
|
|
27
|
|
201769
|
use MooseX::StrictConstructor 0.13; |
|
27
|
|
|
|
|
363024
|
|
|
27
|
|
|
|
|
170
|
|
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
|
46
|
sub delete { return $_[0] } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub from { |
35
|
6
|
|
|
6
|
1
|
674
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
6
|
100
|
|
|
|
17
|
my $count = @_ ? @_ : 1; |
38
|
6
|
|
|
|
|
29
|
my (@tables) = pos_validated_list( |
39
|
|
|
|
|
|
|
\@_, |
40
|
|
|
|
|
|
|
( ( { isa => Table } ) x $count ), |
41
|
|
|
|
|
|
|
MX_PARAMS_VALIDATE_NO_CACHE => 1, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
3206
|
$self->_set_from( \@tables ); |
45
|
|
|
|
|
|
|
|
46
|
5
|
|
|
|
|
28
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub sql { |
50
|
3
|
|
|
3
|
1
|
29
|
my $self = shift; |
51
|
3
|
|
|
|
|
17
|
my ($dbh) = pos_validated_list( \@_, { isa => CanQuote } ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return ( |
54
|
3
|
|
|
|
|
151
|
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
|
30
|
return 'DELETE FROM ' . $_[0]->_tables_subclause( $_[1] ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _tables_subclause { |
67
|
|
|
|
|
|
|
return ( |
68
|
6
|
|
|
|
|
258
|
join ', ', |
69
|
5
|
|
|
5
|
|
8
|
map { $_[1]->quote_identifier( $_->name() ) } @{ $_[0]->_from() } |
|
5
|
|
|
|
|
142
|
|
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.43 |
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 |