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 used for retrieve metadata.
__get(string $fieldName) : \salt\SqlExpr
string
name of the field
\salt\SqlExpr
the field as an SqlExprabsoluteDatabase(string $database) : static
Can be used to make join between tables of different database in same schema
string
the name of the other database
static
current queryallowEmptyWhere(boolean $value = TRUE
)
boolean
Optional : TRUE. Use FALSE for forbidden again empty where after an allow
allowMultipleChange(boolean $value = TRUE
)
boolean
Optional : TRUE. Use FALSE for forbidden again multiple update after an allow
decrement(string $fieldName, integer $value = 1
)
string
fieldName to decrement
integer
default 1
disableIfEmpty(mixed $list)
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 $q->disabledIfEmpty($values); $db->execQuery($q); // valid, will not execute query, so not throw exception
mixed
escapeName(string $name) : string
string
a SQL name : database, table, field, alias, etc...
string
SQL escaped text with backquote.getBindingClass() : string
string
the class of object the query work ongetBinds(string $source = \salt\ClauseType::ALL
) : array<mixed,mixed[]>
string
(Optional) ClauseType or specific text for restrict returned binds to specified source
array<mixed,mixed[]>
list of binds : array of array('value' => ..., 'type' => ...)getPaginationBinds(\salt\Pagination $pagination) : array<mixed,mixed[]>
\salt\Pagination
the Pagination object
array<mixed,mixed[]>
binds for the Pagination : array of bindName => array of ('value' => ..., 'type' => ...)getSelect(string $alias) : \salt\SqlExpr
Example :
$query->select(SqlExpr::_count('*'), 'nb'); $query->orderDesc($query->getSelect('nb'));
string
name of an alias
\salt\SqlExpr
the expression for this aliasgetSelectFields() : 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, integer $value = 1
)
string
fieldName to increment
integer
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 populatedisEnabled() : boolean
boolean
TRUE if the query can be executed, FALSE otherwiseisPrivateBinds() : boolean
boolean
TRUE if privateBinds has been calledisSimpleQuery() : 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...
\salt\SaltException |
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
\salt\SaltException |
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
\salt\SaltException |
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...
\salt\SaltException |
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
privateBinds(boolean $privateBinds = TRUE
) : \salt\SqlBindField
boolean
(Optional, TRUE) hide binds values in debug queries
\salt\SqlBindField
the current objectselect(\salt\SqlExpr $expr, string $as = NULL
)
\salt\SqlExpr
expression to add in select clause, of any type
string
alias for the expression
\salt\SaltException |
---|
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, mixed|\salt\SqlExpr $expr)
string
fieldName to set
mixed
\salt\SqlExpr
the value
toCountQuery() : \salt\CountQuery
Have to be overrided by child classes if needed
\salt\SaltException |
if called on BaseQuery instance |
---|
\salt\CountQuery
the SQL query for count querytoSQL() : string
string
the memoized SQL textwhereAnd(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 $source = \salt\ClauseType::ALL
) : string
mixed
value of bind
integer
(FieldType) type of the field
string
(Optional) ClauseType or other text : clause where the bind will be used, if we know it
string
the bind namebuildGroupClause() : string
string
SQL text for GROUP BY partbuildJoinClause() : string
string
SQL text query with JOIN partbuildOrderClause() : string
string
SQL text for ORDER BY partbuildSQL() : string
string
the SQL textbuildSelectClause() : string
string
SQL text of all retrieved fieldsbuildWhereClause() : string
string
SQL text query with WHERE partlinkBindsOf(\salt\SqlBindField $other, string $source= \salt\ClauseType::ALL
, string $otherSource= \salt\ClauseType::ALL
)
\salt\SqlBindField
the other SqlBindField to link
string
clause usage of the SqlBindField if we known it
string
restrict link to this source in $other
\salt\SaltException |
if this SqlBindField is already resolved |
---|
removeBinds(string $source)
string
ClauseType of specific text
resolveFieldName(string $source, mixed|\salt\SqlExpr $fieldNameOrValue, mixed|\salt\SqlExpr $fieldOfValue = NULL
) : string | array<mixed,string>
string
caller of resolve : ClauseType or specific text
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)toBaseSQL() : string
string
SQL text query with common parts onlyaddJoin(\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 or subquery, with alias
boolean
TRUE if we have to add fields, where, group by, order clause to main query
\salt\SaltException |
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
\salt\SaltException |
if join don't exists |
---|
addJoinOnClause(\salt\Query $other, string $type, string $onClause)
\salt\Query
the other query for retrieve the join clause
string
type of ON clause : AND|OR
string
ON clause
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()
checkNotResolved()
\salt\SaltException |
if called after toSQL() |
---|
getFieldType(string $field) : integer
string
the fieldName
integer
FiedType type of the field$_salt_alias : string
NULL
$_salt_allowEmptyWhere : boolean
FALSE
$_salt_allowMultiple : boolean
FALSE
$_salt_database : string
NULL
$_salt_fields : array<mixed,mixed>
array()
content | array of array(SqlExpr, alias) |
---|
$_salt_groups : array<mixed,string>
array()
$_salt_joins : array<mixed,mixed>
array()
content | array of string => array( // key is table alias for join '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 ) |
---|
$_salt_noAlias : boolean
FALSE
$_salt_obj : \salt\Base
$_salt_orders : array<mixed,string>
array()
content | field ASC|DESC |
---|
$_salt_tableAliasNumber : integer
0
$_salt_wheres : array<mixed,string>
array()
content | AND / OR are parts of $where elements |
---|
$_salt_bindNumber : integer
0
$_salt_bindPaginationNumber : integer
0
$_salt_binds : array<mixed,mixed>
array()
content | array of bindName => array( 'value' => mixed // value of bind 'type' => int FieldType // type of field 'private' => boolean // if value is private data (like passwords) ) |
---|
$_salt_enabled : boolean
TRUE
$_salt_others : array<mixed,\salt\SqlBindField[][]>
array()
content | array of (ClauseType (source) => array of ClauseType(dest) => array of SqlBindField) |
---|
$_salt_privateBinds : boolean
FALSE
$_salt_sets : array<mixed,mixed>
array()
$_salt_sources : array<mixed,string[]>
array()
content | array of (ClauseType => array of bindName) |
---|
$_salt_text : string
NULL