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
protectedarray
List of columns to ensure are part of the insert. -
$_query
protectedCake\Database\Query
|nullThe Query object to use as a values expression -
$_values
protectedarray
Array of values to insert.
Inherited Properties
Method Summary
-
__construct() public
Constructor -
_columnNames() protected
Get the bare column names. -
_processExpressions() protected
Converts values that need to be casted to expressions -
add() public
Add 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() public
Gets 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() public
Gets 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() public
Sets 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() public
Sets the values to be inserted. -
sql() public
Convert the values into a SQL string with placeholders. -
traverse() public
Traverse 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() 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() 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
_processExpressions() protected ¶
_processExpressions( )
Converts values that need to be casted to expressions
add() 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
columns() 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
Parameters
- array|null $cols optional null
- Array with columns to be inserted.
Returns
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
|nullquery() 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
Parameters
-
Cake\Database\Query
$query optional null - The query to set
Returns
setColumns() public ¶
setColumns( array $cols )
Sets the columns to be inserted.
Parameters
- array $cols
- Array with columns to be inserted.
Returns
$this
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
$this
setValues() public ¶
setValues( array $values )
Sets the values to be inserted.
Parameters
- array $values
- Array with values to be inserted.
Returns
$this
sql() public ¶
sql( Cake\Database\ValueBinder $generator )
Convert the values into a SQL string with placeholders.
Parameters
- Cake\Database\ValueBinder $generator
- Placeholder generator object
Returns
Implementation of
traverse() 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
Methods used from Cake\Database\Type\ExpressionTypeCasterTrait
_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 $type
- The type name
Returns
_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
Methods used from Cake\Database\TypeMapTrait
defaultTypes() public ¶
defaultTypes( array $types null )
Allows setting default types when chaining query
Deprecated
Parameters
- array $types optional null
- The array of types to set.
Returns
$this|array
setDefaultTypes() public ¶
setDefaultTypes( array $types )
Allows setting default types when chaining query.
Parameters
- array $types
- The array of types to set.
Returns
$this
setTypeMap() 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() 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
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
$_castedExpressions ¶
Whether or not values have been casted to expressions already.
false