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.
Properties summary
-
$_castedExpressions protected
boolWhether or not values have been casted to expressions already.
-
$_columns protected
arrayList of columns to ensure are part of the insert.
-
$_query protected
\Cake\Database\Query|nullThe Query object to use as a values expression
-
$_typeMap protected
\Cake\Database\TypeMap -
$_values protected
arrayArray of values to insert.
Method Summary
-
__construct() public
Constructor
-
_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.
-
_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.
-
add() public
Add a row of data to be inserted.
-
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.
-
setColumns() public
Sets the columns to be inserted.
-
setDefaultTypes() public
Overwrite the default type mappings for fields in the implementing object.
-
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
Convert the values into a SQL string with placeholders.
-
traverse() public
Traverse the values expression.
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
_castToExpression() protected ¶
_castToExpression(mixed $value, ?string $type)
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 converto to ExpressionInterface
-
string|null$type optional The type name
Returns
mixed_columnNames() protected ¶
_columnNames()
Get the bare column names.
Because column names could be identifier quoted, we need to strip the identifiers off of the columns.
Returns
array_processExpressions() protected ¶
_processExpressions()
Converts values that need to be casted to expressions
_requiresToExpressionCasting() protected ¶
_requiresToExpressionCasting(array $types)
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
arrayadd() public ¶
add(mixed $data)
Add a row of data to be inserted.
Parameters
-
array|\Cake\Database\Query$data Array of data to append into the insert, or a query for doing INSERT INTO .. SELECT style commands
Throws
Cake\Database\ExceptionWhen mixing array + Query data types.
getQuery() public ¶
getQuery()
Gets the query object to be used as the values expression to be evaluated to insert records in the table.
Returns
\Cake\Database\Query|nullsetColumns() public ¶
setColumns(array $cols)
Sets the columns to be inserted.
Parameters
-
array$cols Array with columns to be inserted.
Returns
$thissetDefaultTypes() public ¶
setDefaultTypes(array $types)
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$types The array of types to set.
Returns
$thisSee Also
setQuery() public ¶
setQuery(\Cake\Database\Query $query)
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(mixed $typeMap)
Creates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
Parameters
-
array|\Cake\Database\TypeMap$typeMap Creates a TypeMap if array, otherwise sets the given TypeMap
Returns
$thissetValues() public ¶
setValues(array $values)
Sets the values to be inserted.
Parameters
-
array$values Array with values to be inserted.
Returns
$thissql() public ¶
sql(\Cake\Database\ValueBinder $generator)
Convert the values into a SQL string with placeholders.
Parameters
-
\Cake\Database\ValueBinder$generator Placeholder generator object
Returns
stringtraverse() public ¶
traverse(\Closure $visitor)
Traverse the values expression.
This method will also traverse any queries that are to be used in the INSERT values.
Parameters
-
\Closure$visitor The visitor to traverse the expression with.
Returns
$thisProperty Detail
$_castedExpressions ¶ protected
Whether or not values have been casted to expressions already.
Type
bool