class SQLAssignmentRow (View source)

Represents a list of updates / inserts made to a single row in a table

Properties

protected array $assignments

List of field values to store for this query

Methods

public
__construct(array $values = [])

Instantiate a new SQLAssignmentRow object with the given values

protected
array
parseAssignment(mixed $value)

Given a key / value pair, extract the predicate and any potential parameters in a format suitable for storing internally as a list of paramaterised conditions.

protected
array
normaliseAssignments(array $assignments)

Given a list of assignments in any user-acceptible format, normalise the value to a common ['SQL' => [parameters]] format

public
$this
addAssignments(array $assignments)

Adds assignments for a list of several fields

public
$this
setAssignments(array $assignments)

Sets the list of assignments to the given list

public
array
getAssignments()

Retrieves the list of assignments in parameterised format

public
$this
assign(string $field, mixed $value)

Set the value for a single field

public
$this
assignSQL(string $field, string $sql)

Assigns a value to a field using the literal SQL expression, rather than a value to be escaped

public
bool
isEmpty()

Determine if this assignment is empty

public
array
getColumns()

Retrieves the list of columns updated

public
$this
clear()

Clears all assignment values

Details

__construct(array $values = [])

Instantiate a new SQLAssignmentRow object with the given values

Parameters

array $values

protected array parseAssignment(mixed $value)

Given a key / value pair, extract the predicate and any potential parameters in a format suitable for storing internally as a list of paramaterised conditions.

Parameters

mixed $value

Either a literal field value, or an array with placeholder => parameter(s) as a pair

Return Value

array

A single item array in the format [$sql => [$parameters]]

protected array normaliseAssignments(array $assignments)

Given a list of assignments in any user-acceptible format, normalise the value to a common ['SQL' => [parameters]] format

Parameters

array $assignments

List of assignments. The key of this array should be the field name, and the value the assigned literal value, or an array with parameterised information.

Return Value

array

List of normalised assignments

$this addAssignments(array $assignments)

Adds assignments for a list of several fields

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()' => []]
]);

Parameters

array $assignments

The list of fields to assign

Return Value

$this

The self reference to this row

$this setAssignments(array $assignments)

Sets the list of assignments to the given list

Parameters

array $assignments

Return Value

$this

The self reference to this row

See also

SQLWriteExpression::addAssignments for syntax examples

array getAssignments()

Retrieves the list of assignments in parameterised format

Return Value

array

List of assignments. The key of this array will be the column to assign, and the value a parameterised array in the format ['SQL' => [parameters]];

$this assign(string $field, mixed $value)

Set the value for a single field

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]]);

Parameters

string $field

The field name to update

mixed $value

The value to assign to this field. This could be an array containing a parameterised SQL query of any number of parameters, or a single literal value.

Return Value

$this

The self reference to this row

$this assignSQL(string $field, string $sql)

Assigns a value to a field using the literal SQL expression, rather than a value to be escaped

Parameters

string $field

The field name to update

string $sql

The SQL to use for this update. E.g. "NOW()"

Return Value

$this

The self reference to this row

bool isEmpty()

Determine if this assignment is empty

Return Value

bool

Flag indicating that this assignment is empty

array getColumns()

Retrieves the list of columns updated

Return Value

array

$this clear()

Clears all assignment values

Return Value

$this

The self reference to this row