SQLInsert
class SQLInsert extends SQLExpression implements SQLWriteExpression
Object representing a SQL INSERT query.
The various parts of the SQL query can be manipulated individually.
Methods
Swap some text in the SQL query with another.
Determine if this query is empty, and thus cannot be executed
Generate the SQL statement for this query.
Construct a new SQLInsert object
Construct a new SQLInsert object
Sets the table name to insert into
Gets the table name to insert into
Returns the current list of rows
Returns the list of distinct column names used in this insert
Sets all rows to the given array
Adds the list of rows to the array
Returns the currently set row
Adds assignments for a list of several fields.
Sets the list of assignments to the given list
Retrieves the list of assignments in parameterised format
Set the value for a single field
Assigns a value to a field using the literal SQL expression, rather than a value to be escaped
Clears all currently set assigment values on the current row
Clears all rows
Details
in SQLExpression at line 39
replaceText(string $old, string $new)
Swap some text in the SQL query with another.
Note that values in parameters will not be replaced
in SQLExpression at line 52
string
__toString()
Return the generated SQL string for this query
in SQLExpression at line 71
renameTable(string $old, string $new)
Swap the use of one table with another.
at line 76
bool
isEmpty()
Determine if this query is empty, and thus cannot be executed
in SQLExpression at line 91
string
sql(array $parameters = array())
Generate the SQL statement for this query.
in SQLExpression at line 112
Query
execute()
Execute this query.
at line 35
static SQLInsert
create(string $into = null, array $assignments = array())
Construct a new SQLInsert object
at line 46
__construct(string $into = null, array $assignments = array())
Construct a new SQLInsert object
at line 60
$this
setInto(string $into)
Sets the table name to insert into
at line 71
string
getInto()
Gets the table name to insert into
at line 87
$this
addRow(array|SQLAssignmentRow $data = null)
Appends a new row to insert
at line 108
SQLAssignmentRow[]
getRows()
Returns the current list of rows
at line 118
array
getColumns()
Returns the list of distinct column names used in this insert
at line 133
$this
setRows(array $rows)
Sets all rows to the given array
at line 144
$this
addRows(array $rows)
Adds the list of rows to the array
at line 158
SQLAssignmentRow|false
currentRow(boolean $create = false)
Returns the currently set row
at line 167
$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(array(
'"Object"."Title"' => 'Bob',
'"Object"."Description"' => 'Bob was here'
))
// Parameterised assignments
$query->addAssignments(array(
'"Object"."Title"' => array('?' => 'Bob')),
'"Object"."Description"' => array('?' => null))
))
// Complex parameters
$query->addAssignments(array(
'"Object"."Score"' => array('MAX(?,?)' => array(1, 3))
));
// Assigment of literal SQL for a field. The empty array is
// important to denote the zero-number paramater list
$query->addAssignments(array(
'"Object"."Score"' => array('NOW()' => array())
));
at line 173
$this
setAssignments(array $assignments)
Sets the list of assignments to the given list
For multi-row objects this applies this to the current row.
at line 179
array
getAssignments()
Retrieves the list of assignments in parameterised format
For multi-row objects returns assignments for the current row.
at line 184
$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"', array('?' => 'Bob'));
// Complex parameters
$query->assign('"Object"."Score"', array('MAX(?,?)' => array(1, 3));
at line 190
$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.
at line 201
$this
clearRow()
Clears all currently set assigment values on the current row
at line 212
$this
clear()
Clears all rows