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
Method Summary
-
__construct() public
Constructor
-
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
-
defaultTypes() public
Allows setting default types when chaining query
-
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
-
sql() public
Convert the values into a SQL string with placeholders.
-
traverse() public
Traverse the values expression.
-
typeMap() public
Creates a new TypeMap if $typeMap is an array, otherwise returns the existing type map or exchanges it for the given one.
-
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
add() ¶ public
add(arrayCake\Database\Query $data): void
Add a row of data to be inserted.
Parameters
-
arrayCake\Database\Query
$data Array of data to append into the insert, or a query for doing INSERT INTO .. SELECT style commands
Returns
void
Throws
Cake\Database\Exception
When mixing array + Query data types.
columns() ¶ public
columns(array|null $cols = null): array|$this
Sets the columns to be inserted. If no params are passed, then it returns the currently stored columns
Parameters
-
array|null
$cols optional arrays with columns to be inserted
Returns
array|$this
defaultTypes() ¶ public
defaultTypes(array|null $types = null): $this|array
Allows setting default types when chaining query
Parameters
-
array|null
$types optional The array of types to set.
Returns
$this|array
query() ¶ public
query(Cake\Database\Query|null $query = null): Cake\Database\Query
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
Parameters
-
Cake\Database\Query|null
$query optional The query to set/get
Returns
Cake\Database\Query
sql() ¶ public
sql(Cake\Database\ValueBinder $generator): string
Convert the values into a SQL string with placeholders.
Parameters
-
Cake\Database\ValueBinder
$generator Placeholder generator object
Returns
string
traverse() ¶ public
traverse(callable $visitor): void
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.
Returns
void
typeMap() ¶ public
typeMap(arrayCake\Database\TypeMap|null $typeMap = null): $thisCake\Database\TypeMap
Creates a new TypeMap if $typeMap is an array, otherwise returns the existing type map or exchanges it for the given one.
Parameters
-
arrayCake\Database\TypeMap|null
$typeMap optional Creates a TypeMap if array, otherwise sets the given TypeMap
Returns
$thisCake\Database\TypeMap
values() ¶ public
values(array|null $values = null): array|$this
Sets the values to be inserted. If no params are passed, then it returns the currently stored values
Parameters
-
array|null
$values optional arrays with values to be inserted
Returns
array|$this