Fey::SQL::Insert(3)

NAME
Fey::SQL::Insert - Represents a INSERT query

VERSION
version 0.44

SYNOPSIS
  my $sql = Fey::SQL->new_insert();

  # INSERT INTO Part
  #             (part_id, name, quantity)
  #      VALUES
  #             (?, ?, ?)
  $sql->insert()->into($Part);

  my $ph = Fey::Placeholder->new();

  $sql->values( part_id  => $ph,
                name     => $ph,
                quantity => $ph,
              );

  print $sql->sql($dbh);

DESCRIPTION
This class represents a "INSERT" query.

METHODS
This class provides the following methods:

  Constructor
To construct an object of this class, call "$query->insert()" on a "Fey::SQL" object.

  $insert->insert()
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.

  $insert->into()
This method specifies the "INTO" clause of the query. It expects a list of Fey::Column and/or Fey::Table objects, but not aliases.

If you pass a table object, then the "INTO" will include all of that table's columns, in the order returned by the "$table->columns()" method.

Most RDBMS implementations only allow for a single table here, but some (like MySQL) do allow for multi-table inserts.

  $insert->values(...)
This method takes a hash where the keys are column names, and values are the value to be inserted for that column. Each value can be of the following:

•   a plain scalar, including undef

    This will be passed to "Fey::Literal->new_from_scalar()".

•   "Fey::Literal" object

•   "Fey::Placeholder" object

You can call this method multiple times in order to do a multi-row insert.

  $insert->sql()
Returns the full SQL statement which this object represents. A DBI handle must be passed so that identifiers can be properly quoted.

  $insert->bind_params()
See the Fey::SQL section on Bind Parameters for more details.

  $insert->insert_clause()
Returns the "INSERT INTO" clause portion of the SQL statement as a string (just the tables).

  $insert->columns_clause()
Returns the portion of the SQL statement containing the columns for which values are being inserted as a string.

  $insert->values_clause()
Returns the "VALUES" clause portion of the SQL statement as a string.

ROLES

•   Fey::Role::SQL::HasBindParams

•   Fey::Role::SQL::Cloneable

BUGS
See Fey for details on how to report bugs.

Bugs may be submitted at <https://github.com/ap/Fey/issues>.

SOURCE
The source code repository for Fey can be found at <https://github.com/ap/Fey>.

AUTHOR
Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE
This software is Copyright (c) 2011 - 2025 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the LICENSE file included with this distribution.