Query for UPDATE
package | salt\sql\queries |
---|---|
inherited_from | \salt\Query |
__construct(\salt\Base $obj, \salt\Query $fromQuery = NULL
)
If $obj parameter was retrieve by a SELECT query, you can reuse this query in $fromQuery for update the same object.
inherited_from | \salt\Query::__construct() |
---|
\salt\Base
the object to update
\salt\Query
NULL or a query for initializing WHERE, JOINS and ORDER clauses.
__construct(\salt\Base $obj)
\salt\Base
the object is used for retrieve metadata.
allowEmptyWhere(boolean $value = TRUE
)
boolean
Optional : TRUE. Use FALSE for forbidden again empty where after an allow
allowMultipleUpdate(boolean $value = TRUE
)
boolean
Optional : TRUE. Use FALSE for forbidden again multiple update after an allow
decrement(string $fieldName, \salt\number $value = 1
)
string
fieldName to decrement
\salt\number
default 1
forceEmptyResults()
This can be used if the query contains an IN where condition with an empty array : Executing the query result in an exception, but we can use this function for return an empty result without exception :
$q->whereAnd('ids', 'IN', $values); // will produce a bad where clause : "ids IN ()" if $values is empty if (count($values) === 0) $q->forceEmptyResults(); $db->execQuery($q); // valid, will not execute query, so not throw exception
getBindingClass() : string
string
the class of object the query work ongetBinds() : array<mixed,mixed[]>
array<mixed,mixed[]>
list of binds : array of array('value' => ..., 'type' => ...)getField(string $field) : \salt\SqlExpr
string
the field name to get
\salt\SqlExpr
the SqlExpr of the fieldgetSelectFields() : array<mixed,string>
array<mixed,string>
array of all fields or aliases selected by the querygetSubQuery() : \salt\Query
\salt\Query
a query on the same table with the same alias for using in whereAndQuery or whereOrQuerygroupBy(string|\salt\SqlExpr $fieldOrExpr)
string
\salt\SqlExpr
field name to group by
increment(string $fieldName, \salt\number $value = 1
)
string
fieldName to increment
\salt\number
default 1
initResults(\salt\Pagination $pagination= NULL
, string $count= null
) : \salt\DBResult
\salt\Pagination
pagination object to update
string
total number of elements. Set on pagination
\salt\DBResult
with selected columns populatedisEmptyResults()
isSimpleQuery() : boolean
boolean
TRUE if the update is not multiple and modify only 1 objectjoin(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr, string $type = 'INNER'
)
..
\salt\Query
the other query to join with
string
\salt\SqlExpr
field of ON clause
string
operator of ON clause
mixed
\salt\SqlExpr
value of ON clause
string
type of join: 'INNER', 'OUTER', etc...
\Exception |
if this join already exists |
---|
joinOnAnd(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr)
\salt\Query
the other query for retrieve the join clause
string
\salt\SqlExpr
field of ON clause
string
operator of ON clause
mixed
\salt\SqlExpr
value of ON clause
\Exception |
if join don't exists |
---|
joinOnAndQuery(\salt\Query $other, \salt\Query $whereQuery)
\salt\Query
the other query for retrieve the join clause
\salt\Query
the query to add in ON clause
joinOnOr(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr)
\salt\Query
the other query for retrieve the join clause
string
\salt\SqlExpr
field of ON clause
string
operator of ON clause
mixed
\salt\SqlExpr
value of ON clause
\Exception |
if join don't exists |
---|
joinOnOrQuery(\salt\Query $other, \salt\Query $whereQuery)
\salt\Query
the other query for retrieve the join clause
\salt\Query
the query to add in ON clause
joinSelect(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr, string $type = 'INNER'
)
.. ) tX ON ...
\salt\Query
the other query to join with
string
\salt\SqlExpr
field of ON clause
string
operator of ON clause
mixed
\salt\SqlExpr
value of ON clause
string
type of join: 'INNER', 'OUTER', etc...
\Exception |
if this join already exists |
---|
orderAsc(string|\salt\SqlExpr $fieldOrExpr)
string
\salt\SqlExpr
the field to order by ASC
orderDesc(string|\salt\SqlExpr $fieldOrExpr)
string
\salt\SqlExpr
the field to order by DESC
select(\salt\SqlExpr $expr, string $as = NULL
)
\salt\SqlExpr
expression to add in select clause, of any type
string
alias for the expression
\Exception |
---|
selectField(string|\salt\SqlExpr $field, string $as = NULL
)
string
\salt\SqlExpr
a field name to add in select clause. A SqlExpr can also be used if it's a SqlExpr of type FIELD
string
alias if needed
selectFields(array<mixed,string> $fields)
array<mixed,string>
list of fields name to add in select clause
set(string $fieldName, \salt\SqlExpr $expr)
string
fieldName to set
\salt\SqlExpr
the expression
toCountSQL() : string
Have to be overrided by child classes if needed
\salt\SaltException |
if called |
---|
string
the SQL text for count querytoSQL(\salt\Pagination $pagination = NULL
)
toSQL(\salt\Pagination $pagination = NULL
) : string
\salt\Pagination
the object for handle paging
string
the SQL text of the query with bind placeholderswhereAnd(string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExp $valueOrExpr)
string
\salt\SqlExpr
fieldName or SqlExpr
string
operator to use : '=', 'LIKE', 'IN', etc...
mixed
\salt\SqlExp
value or SqlExpr
whereAndExists(\salt\Query $otherQuery, boolean $exists = TRUE
)
\salt\Query
boolean
if FALSE : AND NOT EXISTS (SELECT 1 $otherQuery)
whereAndObject(\salt\Base|array<mixed,\salt\Base> $objects)
\salt\Base
array<mixed,\salt\Base>
Base object or array of Base objects. Objects have to be of the same type than the query
whereAndQuery(\salt\Query $subQuery)
\salt\Query
have to be a query retrieved by getSubQuery()
whereOr(string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExp $valueOrExpr)
string
\salt\SqlExpr
fieldName or SqlExpr
string
operator to use : '=', 'LIKE', 'IN', etc...
mixed
\salt\SqlExp
value or SqlExpr
whereOrExists(\salt\Query $otherQuery, boolean $exists = TRUE
)
\salt\Query
boolean
if FALSE : OR NOT EXISTS (SELECT 1 $otherQuery)
whereOrObject(\salt\Base|array<mixed,\salt\Base> $objects)
\salt\Base
array<mixed,\salt\Base>
Base object or array of Base objects. Objects have to be of the same type than the query
whereOrQuery(\salt\Query $subQuery)
\salt\Query
have to be a query retrieved by getSubQuery()
addBind(mixed $value, integer $type) : string
mixed
value of bind
integer
(FieldType) type of the field
string
the bind nameaddBindsSource(string $source, string|array<mixed,string> $binds)
string
caller of bind (SELECT, WHERE, GROUPBY, etc...)
string
array<mixed,string>
bind name or list of binds name
getBindsBySource(string $sources) : array<mixed,string>
string
... $sources function take unlimited source bind parameters
array<mixed,string>
binds registered with theses sourcesjoinsToSQL() : string
string
SQL text query with JOIN partorderToSQL() : string
string
SQL text for ORDER BY partresolveFieldName(string $source, mixed|\salt\SqlExpr $fieldNameOrValue, mixed|\salt\SqlExpr $fieldOfValue = NULL
) : string | array<mixed,string>
string
caller of resolve : SELECT, WHERE, etc...
mixed
\salt\SqlExpr
a FieldName (string) or SqlExpr or potential value (int, string, array) if 3rd argument is provided
mixed
\salt\SqlExpr
a Field related to the value. Can be a SqlExpr or a string. Can be NULL if 2nd argument is a string fieldName
string
array<mixed,string>
absolute field name (alias.fieldname) or string with bind values or array of bind values if 2nd argument is an array of valuesresolveTable() : string
string
table name, with or without alias (depends on noAlias)setOrRemplaceBind(string $source, mixed $value, integer $type) : string
Only work with 1 bind by source name
string
source of bind
mixed
a value for bind
integer
FieldType
string
the bind added or replacedtoBaseSQL() : string
string
SQL text query with common parts onlywheresToSQL() : string
string
SQL text query with WHERE partaddJoin(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr, string $type= 'INNER'
, string $table, boolean $withOtherDatas= TRUE
)
\salt\Query
the other query to join with
string
\salt\SqlExpr
field of ON clause
string
operator of ON clause
mixed
\salt\SqlExpr
value of ON clause
string
type of join: 'INNER', 'OUTER', etc...
string
object to join with : table name of subquery
boolean
TRUE if we have to add fields, where, group by, order clause to main query
\Exception |
if this join already exists |
---|
addJoinOn(string $type, \salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr)
string
AND|OR
\salt\Query
the other query for retrieve the join clause
string
\salt\SqlExpr
field of ON clause
string
operator of ON clause
mixed
\salt\SqlExpr
value of ON clause
\Exception |
if join don't exists |
---|
addJoinOnQuery(string $type, \salt\Query $other, \salt\Query $whereQuery)
string
AND|OR
\salt\Query
the other query for retrieve the join clause
\salt\Query
the query to add in ON clause
addWhere(string $addType, string|\salt\SqlExpr $fieldOrExpr, string $operator, string|\salt\SqlExpr $valueOrExpr)
string
AND|OR
string
\salt\SqlExpr
fieldName or SqlExpr
string
operator to use : '=', 'LIKE', 'IN', etc...
string
\salt\SqlExpr
value or SqlExpr
addWhereClause(string $type, string $whereClause)
string
type of where clause : AND|OR
string
where clause
addWhereExists(string $type, \salt\Query $otherQuery, boolean $exists = TRUE
)
string
AND|OR
\salt\Query
boolean
if FALSE : NOT EXISTS (SELECT 1 $otherQuery)
addWhereObject(string $type, \salt\Base|array<mixed,\salt\Base> $objects)
string
AND|OR
\salt\Base
array<mixed,\salt\Base>
Base object or array of Base objects. Objects have to be of the same type than the query
addWhereQuery(string $type, \salt\Query $subQuery)
string
OR|AND
\salt\Query
have to be a query retrieved by getSubQuery()
getFieldType(string $field) : integer
string
the fieldName
integer
FiedType type of the field$alias : string
NULL
$allowEmptyWhere : boolean
FALSE
$allowMultiple : boolean
FALSE
$bindNumber : integer
0
$binds : array<mixed,mixed>
array()
content | array of bindName => array( 'value' => mixed // value of bind 'type' => int FieldType // type of field ) |
---|
$bindsSource : \salt\binds
array()
content | array of source => array(binds) |
---|
$emptyResults : boolean
FALSE
$fields : array<mixed,mixed>
array()
content | array of array(SqlExpr, alias) |
---|
$groups : array<mixed,string>
array()
$joins : array<mixed,mixed>
array()
content | array of string => array( // key is table alias for join 'meta' => array of Field // of the joined object 'type' => string // join type 'INNER|OUTER|LEFT INNER|...' 'table' => string // table name or inner select table of the joined object 'on' => array of string // where clauses, like $wheres ) |
---|
$noAlias : boolean
FALSE
$obj : \salt\Base
$orders : array<mixed,string>
array()
content | field ASC|DESC |
---|
$sqlText : string
NULL
$tableAliasNumber : integer
0
$wheres : array<mixed,string>
array()
content | AND / OR are parts of $where elements |
---|
$bindsBySetField : array<mixed,mixed>
array()
content | Register all binds used for each field. If a field is changed twice, previous binds are canceled |
---|
$sets : array<mixed,mixed>
array()