SQLInsert
class SQLInsert extends SQLExpression implements SQLWriteExpression (View source)
Object representing a SQL INSERT query.
The various parts of the SQL query can be manipulated individually.
Properties
protected | array | $replacementsOld | Keep an internal register of find/replace pairs to execute when it's time to actually get the query SQL. |
from SQLExpression |
protected | array | $replacementsNew | Keep an internal register of find/replace pairs to execute when it's time to actually get the query SQL. |
from SQLExpression |
protected | SQLAssignmentRow[] | $rows | List of rows to be inserted |
|
protected | string | $into | The table name to insert into |
Methods
Swap some text in the SQL query with another.
Swap the use of one table with another.
Generate the SQL statement for this query.
Copies the query parameters contained in this object to another SQLExpression
Construct a new SQLInsert object
Assigns a value to a field using the literal SQL expression, rather than a value to be escaped
Details
replaceText(string $old, string $new)
Swap some text in the SQL query with another.
Note that values in parameters will not be replaced
string
__toString()
Return the generated SQL string for this query
renameTable(string $old, string $new)
Swap the use of one table with another.
bool
isEmpty()
Determine if this query is empty, and thus cannot be executed
string
sql(array $parameters = [])
Generate the SQL statement for this query.
Query
execute()
Execute this query.
protected
copyTo(SQLExpression $object)
Copies the query parameters contained in this object to another SQLExpression
static SQLInsert
create(string $into = null, array $assignments = [])
Construct a new SQLInsert object
__construct(string $into = null, array $assignments = [])
Construct a new SQLInsert object
$this
setInto(string $into)
Sets the table name to insert into
string
getInto()
Gets the table name to insert into
$this
addRow(array|SQLAssignmentRow $data = null)
Appends a new row to insert
SQLAssignmentRow[]
getRows()
Returns the current list of rows
array
getColumns()
Returns the list of distinct column names used in this insert
$this
setRows(array $rows)
Sets all rows to the given array
$this
addRows(array $rows)
Adds the list of rows to the array
SQLAssignmentRow|false
currentRow(bool $create = false)
Returns the currently set row
$this
addAssignments(array $assignments)
Adds assignments for a list of several fields.
For multi-row objects this applies this to the current row.
Note that field values must not be escaped, as these will be internally parameterised by the database engine.
// Basic assignments
$query->addAssignments([
'"Object"."Title"' => 'Bob',
'"Object"."Description"' => 'Bob was here'
])
// Parameterised assignments
$query->addAssignments([
'"Object"."Title"' => ['?' => 'Bob'],
'"Object"."Description"' => ['?' => null]
])
// Complex parameters
$query->addAssignments([
'"Object"."Score"' => ['MAX(?,?)' => [1, 3]]
]);
// Assignment of literal SQL for a field. The empty array is
// important to denote the zero-number parameter list
$query->addAssignments([
'"Object"."Score"' => ['NOW()' => []]
]);
$this
setAssignments(array $assignments)
Sets the list of assignments to the given list
For multi-row objects this applies this to the current row.
array
getAssignments()
Retrieves the list of assignments in parameterised format
For multi-row objects returns assignments for the current row.
$this
assign(string $field, mixed $value)
Set the value for a single field
For multi-row objects this applies this to the current row.
E.g.
// Literal assignment
$query->assign('"Object"."Description"', 'lorum ipsum'));
// Single parameter
$query->assign('"Object"."Title"', ['?' => 'Bob']);
// Complex parameters
$query->assign('"Object"."Score"', ['MAX(?,?)' => [1, 3]]);
$this
assignSQL(string $field, string $sql)
Assigns a value to a field using the literal SQL expression, rather than a value to be escaped
For multi-row objects this applies this to the current row.
$this
clearRow()
Clears all currently set assignment values on the current row
$this
clear()
Clears all rows