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.
- Cake\Database\Expression\ValuesExpression implements Cake\Database\ExpressionInterface uses Cake\Database\Type\ExpressionTypeCasterTrait , Cake\Database\TypeMapTrait
Properties summary
-
$_castedExpressions
protectedboolean
Whether or not values have been casted to expressions already.
-
$_columns
protectedList of columns to ensure are part of the insert.array
-
$_query
protectedThe Query object to use as a values expressionCake\Database\Query|null
-
$_values
protectedArray of values to insert.array
Inherited Properties
Method Summary
- __construct() publicConstructor
- _columnNames() protectedGet the bare column names.
- _processExpressions() protectedConverts values that need to be casted to expressions
- add() publicAdd a row of data to be inserted.
- columns() public
Sets the columns to be inserted. If no params are passed, then it returns the currently stored columns.
- getColumns() publicGets the columns to be inserted.
- getQuery() public
Gets the query object to be used as the values expression to be evaluated to insert records in the table.
- getValues() publicGets the values to be inserted.
- query() public
Sets the query object to be used as the values expression to be evaluated to insert records in the table. If no params are passed, then it returns the currently stored query
- setColumns() publicSets the columns to be inserted.
- setQuery() public
Sets the query object to be used as the values expression to be evaluated to insert records in the table.
- setValues() publicSets the values to be inserted.
- sql() publicConvert the values into a SQL string with placeholders.
- traverse() publicTraverse the values expression.
- values() public
Sets the values to be inserted. If no params are passed, then it returns the currently stored values
Method Detail
__construct()source 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
_columnNames()source 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()source protected
_processExpressions( )
Converts values that need to be casted to expressions
add()source public
add( array|Cake\Database\Query $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\Exception
When mixing array + Query data types.
columns()source public
columns( array|null $cols null )
Sets the columns to be inserted. If no params are passed, then it returns the currently stored columns.
Deprecated
3.4.0 Use setColumns()/getColumns() instead.Parameters
- array|null
$cols
optional null - Array with columns to be inserted.
Returns
array|Cake\Database\Expression\ValuesExpression
$this
getQuery()source 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
query()source public
query( Cake\Database\Query $query null )
Sets the query object to be used as the values expression to be evaluated to insert records in the table. If no params are passed, then it returns the currently stored query
Deprecated
3.4.0 Use setQuery()/getQuery() instead.Parameters
-
Cake\Database\Query
$query
optional null - The query to set
Returns
Cake\Database\Query
|null|Cake\Database\Expression\ValuesExpression
$this
setColumns()source public
setColumns( array $cols )
Sets the columns to be inserted.
Parameters
- array
$cols
- Array with columns to be inserted.
Returns
$this
setQuery()source 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
$this
setValues()source public
setValues( array $values )
Sets the values to be inserted.
Parameters
- array
$values
- Array with values to be inserted.
Returns
$this
sql()source public
sql( Cake\Database\ValueBinder $generator )
Convert the values into a SQL string with placeholders.
Parameters
- Cake\Database\ValueBinder
$generator
- Placeholder generator object
Returns
stringImplementation of
Cake\Database\ExpressionInterface::sql()
traverse()source public
traverse( callable $visitor )
Traverse the values expression.
This method will also traverse any queries that are to be used in the INSERT values.
Parameters
- callable
$visitor
- The visitor to traverse the expression with.
Implementation of
Cake\Database\ExpressionInterface::traverse()
values()source public
values( array|null $values null )
Sets the values to be inserted. If no params are passed, then it returns the currently stored values
Deprecated
3.4.0 Use setValues()/getValues() instead.Parameters
- array|null
$values
optional null - Array with values to be inserted.
Returns
array|Cake\Database\Expression\ValuesExpression
$this
Methods used from Cake\Database\Type\ExpressionTypeCasterTrait
_castToExpression()source 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
$type
- The type name
Returns
mixed_requiresToExpressionCasting()source 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
arrayMethods used from Cake\Database\TypeMapTrait
defaultTypes()source public
defaultTypes( array $types null )
Allows setting default types when chaining query
Deprecated
3.4.0 Use setDefaultTypes()/getDefaultTypes() instead.Parameters
- array
$types
optional null - The array of types to set.
Returns
$this|array
getDefaultTypes()source public
getDefaultTypes( )
Gets default types of current type map.
Returns
arraygetTypeMap()source public
getTypeMap( )
Returns the existing type map.
Returns
Cake\Database\TypeMap
setDefaultTypes()source public
setDefaultTypes( array $types )
Allows setting default types when chaining query.
Parameters
- array
$types
- The array of types to set.
Returns
$this
setTypeMap()source public
setTypeMap( array|Cake\Database\TypeMap $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
$this
typeMap()source public
typeMap( array|Cake\Database\TypeMap|null $typeMap null )
Creates a new TypeMap if $typeMap is an array, otherwise returns the existing type map or exchanges it for the given one.
Deprecated
3.4.0 Use setTypeMap()/getTypeMap() instead.Parameters
- array|
Cake\Database\TypeMap
|null$typeMap
optional null - Creates a TypeMap if array, otherwise sets the given TypeMap
Returns
$this|\Cake\Database\TypeMap
Properties detail
$_castedExpressionssource
protected boolean
Whether or not values have been casted to expressions already.
false
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.Database.Expression.ValuesExpression.html