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