ValuesExpression
in package
implements
ExpressionInterface
uses
ExpressionTypeCasterTrait, TypeMapTrait
An expression object to contain values being inserted.
Helps generate SQL with the correct number of placeholders and bind values correctly into the statement.
Table of Contents
Interfaces
- ExpressionInterface
- An interface used by Expression objects.
Properties
- $_castedExpressions : bool
- Whether values have been casted to expressions already.
- $_columns : array<string|int, mixed>
- List of columns to ensure are part of the insert.
- $_query : Query|null
- The Query object to use as a values expression
- $_typeMap : TypeMap|null
- $_values : array<string|int, mixed>
- Array of values to insert.
Methods
- __construct() : mixed
- Constructor
- add() : void
- Add a row of data to be inserted.
- getColumns() : array<string|int, mixed>
- Gets the columns to be inserted.
- getDefaultTypes() : array<int|string, string>
- Gets default types of current type map.
- getQuery() : Query|null
- Gets the query object to be used as the values expression to be evaluated to insert records in the table.
- getTypeMap() : TypeMap
- Returns the existing type map.
- getValues() : array<string|int, mixed>
- Gets the values to be inserted.
- setColumns() : $this
- Sets the columns to be inserted.
- setDefaultTypes() : $this
- Overwrite the default type mappings for fields in the implementing object.
- setQuery() : $this
- Sets the query object to be used as the values expression to be evaluated to insert records in the table.
- setTypeMap() : $this
- Creates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
- setValues() : $this
- Sets the values to be inserted.
- sql() : string
- Converts the Node into a SQL string fragment.
- traverse() : $this
- Iterates over each part of the expression recursively for every level of the expressions tree and executes the $callback callable passing as first parameter the instance of the expression currently being iterated.
- _castToExpression() : mixed
- Conditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
- _columnNames() : array<string|int, mixed>
- Get the bare column names.
- _processExpressions() : void
- Converts values that need to be casted to expressions
- _requiresToExpressionCasting() : array<string|int, mixed>
- Returns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
Properties
$_castedExpressions
Whether values have been casted to expressions already.
protected
bool
$_castedExpressions
= false
$_columns
List of columns to ensure are part of the insert.
protected
array<string|int, mixed>
$_columns
= []
$_query
The Query object to use as a values expression
protected
Query|null
$_query
$_typeMap
protected
TypeMap|null
$_typeMap
$_values
Array of values to insert.
protected
array<string|int, mixed>
$_values
= []
Methods
__construct()
Constructor
public
__construct(array<string|int, mixed> $columns, TypeMap $typeMap) : mixed
Parameters
- $columns : array<string|int, mixed>
-
The list of columns that are going to be part of the values.
- $typeMap : TypeMap
-
A dictionary of column -> type names
add()
Add a row of data to be inserted.
public
add(Query|array<string|int, mixed> $values) : void
Parameters
- $values : Query|array<string|int, mixed>
-
Array of data to append into the insert, or a query for doing INSERT INTO .. SELECT style commands
Tags
getColumns()
Gets the columns to be inserted.
public
getColumns() : array<string|int, mixed>
Return values
array<string|int, mixed>getDefaultTypes()
Gets default types of current type map.
public
getDefaultTypes() : array<int|string, string>
Return values
array<int|string, string>getQuery()
Gets the query object to be used as the values expression to be evaluated to insert records in the table.
public
getQuery() : Query|null
Return values
Query|nullgetTypeMap()
Returns the existing type map.
public
getTypeMap() : TypeMap
Return values
TypeMapgetValues()
Gets the values to be inserted.
public
getValues() : array<string|int, mixed>
Return values
array<string|int, mixed>setColumns()
Sets the columns to be inserted.
public
setColumns(array<string|int, mixed> $columns) : $this
Parameters
- $columns : array<string|int, mixed>
-
Array with columns to be inserted.
Return values
$thissetDefaultTypes()
Overwrite the default type mappings for fields in the implementing object.
public
setDefaultTypes(array<int|string, string> $types) : $this
This method is useful if you need to set type mappings that are shared across multiple functions/expressions in a query.
To add a default without overwriting existing ones
use getTypeMap()->addDefaults()
Parameters
- $types : array<int|string, string>
-
The array of types to set.
Tags
Return values
$thissetQuery()
Sets the query object to be used as the values expression to be evaluated to insert records in the table.
public
setQuery(Query $query) : $this
Parameters
- $query : Query
-
The query to set
Return values
$thissetTypeMap()
Creates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
public
setTypeMap(TypeMap|array<string|int, mixed> $typeMap) : $this
Parameters
- $typeMap : TypeMap|array<string|int, mixed>
-
Creates a TypeMap if array, otherwise sets the given TypeMap
Return values
$thissetValues()
Sets the values to be inserted.
public
setValues(array<string|int, mixed> $values) : $this
Parameters
- $values : array<string|int, mixed>
-
Array with values to be inserted.
Return values
$thissql()
Converts the Node into a SQL string fragment.
public
sql(ValueBinder $binder) : string
Parameters
- $binder : ValueBinder
-
Parameter binder
Tags
Return values
stringtraverse()
Iterates over each part of the expression recursively for every level of the expressions tree and executes the $callback callable passing as first parameter the instance of the expression currently being iterated.
public
traverse(Closure $callback) : $this
Parameters
- $callback : Closure
-
The callable to apply to all nodes.
Tags
Return values
$this_castToExpression()
Conditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
protected
_castToExpression(mixed $value[, string|null $type = null ]) : mixed
Parameters
- $value : mixed
-
The value to convert to ExpressionInterface
- $type : string|null = null
-
The type name
_columnNames()
Get the bare column names.
protected
_columnNames() : array<string|int, mixed>
Because column names could be identifier quoted, we need to strip the identifiers off of the columns.
Return values
array<string|int, mixed>_processExpressions()
Converts values that need to be casted to expressions
protected
_processExpressions() : void
_requiresToExpressionCasting()
Returns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
protected
_requiresToExpressionCasting(array<string|int, mixed> $types) : array<string|int, mixed>
Parameters
- $types : array<string|int, mixed>
-
List of type names