Class ValuesExpression
An expression object to contain values being inserted.
Helps generate SQL with the correct number of placeholders and bind values correctly into the statement.
Property Summary
-
$castedExpressions protected
boolWhether values have been casted to expressions already.
-
$query protected
Cake\Database\Query|nullThe Query object to use as a values expression
-
$typeMap protected
Cake\Database\TypeMap|null -
$values protected
arrayArray of values to insert.
Method Summary
-
__construct() public
Constructor
-
add() public
Add a row of data to be inserted.
-
castToExpression() protected
Conditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
-
columnNames() protected
Get the bare column names.
Because column names could be identifier quoted, we need to strip the identifiers off of the columns.
-
getColumns() public
Gets the columns to be inserted.
-
getDefaultTypes() public
Gets default types of current type map.
-
getQuery() public
Gets the query object to be used as the values expression to be evaluated to insert records in the table.
-
getTypeMap() public
Returns the existing type map.
-
getValues() public
Gets the values to be inserted.
-
processExpressions() protected
Converts values that need to be casted to expressions
-
requiresToExpressionCasting() protected
Returns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
-
setColumns() public
Sets the columns to be inserted.
-
setDefaultTypes() public
Overwrite the default type mappings for fields in the implementing object.
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() -
setQuery() public
Sets the query object to be used as the values expression to be evaluated to insert records in the table.
-
setTypeMap() public
Creates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
-
setValues() public
Sets the values to be inserted.
-
sql() public
Converts the Node into a SQL string fragment.
-
traverse() public
Iterates over each part of the expression recursively for every level of the expressions tree and executes the callback, passing as first parameter the instance of the expression currently being iterated.
Method Detail
__construct() ¶ public
__construct(array $columns, Cake\Database\TypeMap $typeMap)
Constructor
Parameters
-
array$columns The list of columns that are going to be part of the values.
-
Cake\Database\TypeMap$typeMap A dictionary of column -> type names
add() ¶ public
add(Cake\Database\Query|array $values): void
Add a row of data to be inserted.
Parameters
-
Cake\Database\Query|array$values Array of data to append into the insert, or a query for doing INSERT INTO .. SELECT style commands
Returns
voidThrows
Cake\Database\Exception\DatabaseExceptionWhen mixing array and Query data types.
castToExpression() ¶ protected
castToExpression(mixed $value, string|null $type = null): mixed
Conditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
Parameters
-
mixed$value The value to convert to ExpressionInterface
-
string|null$type optional The type name
Returns
mixedcolumnNames() ¶ protected
columnNames(): array
Get the bare column names.
Because column names could be identifier quoted, we need to strip the identifiers off of the columns.
Returns
arraygetDefaultTypes() ¶ public
getDefaultTypes(): array<int|string, string>
Gets default types of current type map.
Returns
array<int|string, string>getQuery() ¶ public
getQuery(): Cake\Database\Query|null
Gets the query object to be used as the values expression to be evaluated to insert records in the table.
Returns
Cake\Database\Query|nullgetTypeMap() ¶ public
getTypeMap(): Cake\Database\TypeMap
Returns the existing type map.
Returns
Cake\Database\TypeMapprocessExpressions() ¶ protected
processExpressions(): void
Converts values that need to be casted to expressions
Returns
voidrequiresToExpressionCasting() ¶ protected
requiresToExpressionCasting(array $types): array
Returns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
Parameters
-
array$types List of type names
Returns
arraysetColumns() ¶ public
setColumns(array $columns): $this
Sets the columns to be inserted.
Parameters
-
array$columns Array with columns to be inserted.
Returns
$thissetDefaultTypes() ¶ public
setDefaultTypes(array<int|string, string> $types): $this
Overwrite the default type mappings for fields in the implementing object.
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
-
array<int|string, string>$types The array of types to set.
Returns
$thisSee Also
setQuery() ¶ public
setQuery(Cake\Database\Query $query): $this
Sets the query object to be used as the values expression to be evaluated to insert records in the table.
Parameters
-
Cake\Database\Query$query The query to set
Returns
$thissetTypeMap() ¶ public
setTypeMap(Cake\Database\TypeMap|array<int|string, string> $typeMap): $this
Creates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
Parameters
-
Cake\Database\TypeMap|array<int|string, string>$typeMap Creates a TypeMap if array, otherwise sets the given TypeMap
Returns
$thissetValues() ¶ public
setValues(array $values): $this
Sets the values to be inserted.
Parameters
-
array$values Array with values to be inserted.
Returns
$thissql() ¶ public
sql(Cake\Database\ValueBinder $binder): string
Converts the Node into a SQL string fragment.
Parameters
-
Cake\Database\ValueBinder$binder
Returns
stringtraverse() ¶ public
traverse(Closure $callback): $this
Iterates over each part of the expression recursively for every level of the expressions tree and executes the callback, passing as first parameter the instance of the expression currently being iterated.
Parameters
-
Closure$callback
Returns
$this