| Fey documentation | Contained in the Fey distribution. |
Fey::SQL::Delete - Represents a DELETE query
version 0.40
my $sql = Fey::SQL->new_delete(); # DELETE FROM Part # WHERE Part.name LIKE '%Widget' $sql->delete(); $sql->from($Part); $sql->where( $name, 'LIKE', '%Widget' ); print $sql->sql($dbh);
This class represents a DELETE query.
This class provides the following methods:
To construct an object of this class, call $query->delete() on
a Fey::SQL object.
This method is basically a no-op that exists to so that Fey::SQL has something to call after it constructs an object in this class.
This method specifies the FROM clause of the query. It expects one
or more Fey::Table objects (not aliases). Most RDBMS
implementations only allow for a single table here, but some (like
MySQL) do allow for multi-table deletes.
See the Fey::SQL section on WHERE Clauses for more details.
See the Fey::SQL section on ORDER BY Clauses for more details.
See the Fey::SQL section on LIMIT Clauses for more details.
Returns the full SQL statement which this object represents. A DBI handle must be passed so that identifiers can be properly quoted.
See the Fey::SQL section on Bind Parameters for more details.
Returns the DELETE clause portion of the SQL statement as a string.
Returns the WHERE clause portion of the SQL statement as a string.
Returns the ORDER BY clause portion of the SQL statement as a
string.
Returns the LIMIT clause portion of the SQL statement as a string.
See Fey for details on how to report bugs.
Dave Rolsky <autarch@urth.org>
This software is Copyright (c) 2011 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
| Fey documentation | Contained in the Fey distribution. |
package Fey::SQL::Delete; BEGIN { $Fey::SQL::Delete::VERSION = '0.40'; } use strict; use warnings; use namespace::autoclean; use Fey::Types qw( ArrayRef CanQuote Table ); use Scalar::Util qw( blessed ); use Moose; use MooseX::Params::Validate qw( pos_validated_list ); use MooseX::SemiAffordanceAccessor; use MooseX::StrictConstructor; with 'Fey::Role::SQL::HasWhereClause', 'Fey::Role::SQL::HasOrderByClause', 'Fey::Role::SQL::HasLimitClause'; with 'Fey::Role::SQL::HasBindParams' => { -excludes => 'bind_params' }; has '_from' => ( is => 'rw', isa => ArrayRef, default => sub { [] }, init_arg => undef, ); with 'Fey::Role::SQL::Cloneable'; sub delete { return $_[0] } sub from { my $self = shift; my $count = @_ ? @_ : 1; my (@tables) = pos_validated_list( \@_, ( ( { isa => Table } ) x $count ), MX_PARAMS_VALIDATE_NO_CACHE => 1, ); $self->_set_from( \@tables ); return $self; } sub sql { my $self = shift; my ($dbh) = pos_validated_list( \@_, { isa => CanQuote } ); return ( join ' ', $self->delete_clause($dbh), $self->where_clause($dbh), $self->order_by_clause($dbh), $self->limit_clause($dbh), ); } sub delete_clause { return 'DELETE FROM ' . $_[0]->_tables_subclause( $_[1] ); } sub _tables_subclause { return ( join ', ', map { $_[1]->quote_identifier( $_->name() ) } @{ $_[0]->_from() } ); } __PACKAGE__->meta()->make_immutable(); 1; # ABSTRACT: Represents a DELETE query
__END__