Query for DELETE

package salt\sql\queries
inherited_from \salt\UpdateQuery

 Methods

Create a query for delete one or more object

__construct(array<mixed,\salt\Base>|\salt\Base $objects) 

If $obj parameter was retrieve by a SELECT query, you can reuse this query in $fromQuery for update the same object.

inherited_from \salt\UpdateQuery::__construct()

Parameters

$objects

array<mixed,\salt\Base>\salt\Base

object or array of object (of same type) to delete

Construct a new query

__construct(\salt\Base $obj) 
Inherited

Parameters

$obj

\salt\Base

the object used for retrieve metadata.

Retrieve a field as an SqlExpr for reuse it in another query / SqlExpr

__get(string $fieldName) : \salt\SqlExpr
Inherited

Parameters

$fieldName

string

name of the field

Returns

\salt\SqlExprthe field as an SqlExpr

Use database name in table reference.

absoluteDatabase(string $database) : static
Inherited

Can be used to make join between tables of different database in same schema

Parameters

$database

string

the name of the other database

Returns

staticcurrent query

Allow the query to have an empty WHERE clause, which will update all objects in table.

allowEmptyWhere(boolean $value = TRUE
Inherited

Parameters

$value

boolean

Optional : TRUE. Use FALSE for forbidden again empty where after an allow

Allow the query to have an "open" WHERE clause, without the clause on object id added automatically

allowMultipleChange(boolean $value = TRUE
Inherited

Parameters

$value

boolean

Optional : TRUE. Use FALSE for forbidden again multiple update after an allow

Force a SET clause like fieldName = fieldName - X

decrement(string $fieldName, integer $value = 1
Inherited

Parameters

$fieldName

string

fieldName to decrement

$value

integer

default 1

If parameter is empty, the query will not be executed

disableIfEmpty(mixed $list) 
Inherited

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

Parameters

$list

mixed

Escape a name for SQL use with backquote

escapeName(string $name) : string
InheritedStatic

Parameters

$name

string

a SQL name : database, table, field, alias, etc...

Returns

stringSQL escaped text with backquote.

Get the class of the object used to construct to query

getBindingClass() : string
Inherited

Returns

stringthe class of object the query work on

Return all binds

getBinds(string $source = \salt\ClauseType::ALL) : array<mixed,mixed[]>
Inherited

Parameters

$source

string

(Optional) ClauseType or specific text for restrict returned binds to specified source

Returns

array<mixed,mixed[]>list of binds : array of array('value' => ..., 'type' => ...)

Retrieve the number of objects passed in query constructor

getDeletedObjectCount() : integer

Returns

integernumber of objects expected to be deleted

Retrieve binds for pagination (LIMIT clause)

getPaginationBinds(\salt\Pagination $pagination) : array<mixed,mixed[]>
InheritedStatic

Parameters

$pagination

\salt\Pagination

the Pagination object

Returns

array<mixed,mixed[]>binds for the Pagination : array of bindName => array of ('value' => ..., 'type' => ...)

Get a selected expression added in query by an alias for reuse it

getSelect(string $alias) : \salt\SqlExpr
Inherited

Example :

$query->select(SqlExpr::_count('*'), 'nb');
$query->orderDesc($query->getSelect('nb'));

Parameters

$alias

string

name of an alias

Returns

\salt\SqlExprthe expression for this alias

Return the list of field or alias returned by SELECT clause

getSelectFields() : array<mixed,string>
Inherited

Returns

array<mixed,string>array of all fields or aliases selected by the query

Get a sub query of this query

getSubQuery() : \salt\Query
Inherited

Returns

\salt\Querya query on the same table with the same alias for using in whereAndQuery or whereOrQuery

Add a field in GROUP BY clause

groupBy(string|\salt\SqlExpr $fieldOrExpr) 
Inherited

Parameters

$fieldOrExpr

string\salt\SqlExpr

field name to group by

Force a SET clause like fieldName = fieldName + X

increment(string $fieldName, integer $value = 1
Inherited

Parameters

$fieldName

string

fieldName to increment

$value

integer

default 1

Initialize DBResult. Called during query execution.

initResults(\salt\Pagination $pagination = NULL, string $count = NULL) : \salt\DBResult
Inherited

Parameters

$pagination

\salt\Pagination

pagination object to update

$count

string

total number of elements. Set on pagination

Returns

\salt\DBResultwith selected columns populated

Check if we have to execute the query

isEnabled() : boolean
Inherited

Returns

booleanTRUE if the query can be executed, FALSE otherwise

Check binds are private

isPrivateBinds() : boolean
Inherited

Returns

booleanTRUE if privateBinds has been called

Check if UPDATE query update only one object

isSimpleQuery() : boolean
Inherited

Returns

booleanTRUE if the update is not multiple and modify only 1 object

Add a classic join : INNER JOIN table tX ON .

join(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr, string $type = 'INNER'
Inherited

..

Parameters

$other

\salt\Query

the other query to join with

$fieldOrExpr

string\salt\SqlExpr

field of ON clause

$operator

string

operator of ON clause

$valueOrExpr

mixed\salt\SqlExpr

value of ON clause

$type

string

type of join: 'INNER', 'OUTER', etc...

Exceptions

\salt\SaltException if this join already exists

add an ON clause to an existing join

joinOnAnd(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr) 
Inherited

Parameters

$other

\salt\Query

the other query for retrieve the join clause

$fieldOrExpr

string\salt\SqlExpr

field of ON clause

$operator

string

operator of ON clause

$valueOrExpr

mixed\salt\SqlExpr

value of ON clause

Exceptions

\salt\SaltException if join don't exists

add an query to an ON clause of an existing join

joinOnAndQuery(\salt\Query $other, \salt\Query $whereQuery) 
Inherited

Parameters

$other

\salt\Query

the other query for retrieve the join clause

$whereQuery

\salt\Query

the query to add in ON clause

add an ON clause to an existing join

joinOnOr(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr) 
Inherited

Parameters

$other

\salt\Query

the other query for retrieve the join clause

$fieldOrExpr

string\salt\SqlExpr

field of ON clause

$operator

string

operator of ON clause

$valueOrExpr

mixed\salt\SqlExpr

value of ON clause

Exceptions

\salt\SaltException if join don't exists

add an query to an ON clause of an existing join

joinOnOrQuery(\salt\Query $other, \salt\Query $whereQuery) 
Inherited

Parameters

$other

\salt\Query

the other query for retrieve the join clause

$whereQuery

\salt\Query

the query to add in ON clause

Add a join with a select : INNER JOIN (SELECT .

joinSelect(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr, string $type = 'INNER'
Inherited

.. ) tX ON ...

Parameters

$other

\salt\Query

the other query to join with

$fieldOrExpr

string\salt\SqlExpr

field of ON clause

$operator

string

operator of ON clause

$valueOrExpr

mixed\salt\SqlExpr

value of ON clause

$type

string

type of join: 'INNER', 'OUTER', etc...

Exceptions

\salt\SaltException if this join already exists

Add a field in order clause, with ASC

orderAsc(string|\salt\SqlExpr $fieldOrExpr) 
Inherited

Parameters

$fieldOrExpr

string\salt\SqlExpr

the field to order by ASC

Add a field in order clause, with DESC

orderDesc(string|\salt\SqlExpr $fieldOrExpr) 
Inherited

Parameters

$fieldOrExpr

string\salt\SqlExpr

the field to order by DESC

Set all binds values as private. They will be hidden in debug queries

privateBinds(boolean $privateBinds = TRUE) : \salt\SqlBindField
Inherited

Parameters

$privateBinds

boolean

(Optional, TRUE) hide binds values in debug queries

Returns

\salt\SqlBindFieldthe current object

Add a SqlExpr in the SELECT clause

select(\salt\SqlExpr $expr, string $as = NULL
Inherited

Parameters

$expr

\salt\SqlExpr

expression to add in select clause, of any type

$as

string

alias for the expression

Exceptions

\salt\SaltException

Add a field int the SELECT clause

selectField(string|\salt\SqlExpr $field, string $as = NULL
Inherited

Parameters

$field

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

$as

string

alias if needed

Add a list of fields in the SELECT clause

selectFields(array<mixed,string> $fields) 
Inherited

Parameters

$fields

array<mixed,string>

list of fields name to add in select clause

Force a SET clause like fieldName = sql expression

set(string $fieldName, mixed|\salt\SqlExpr $expr) 
Inherited

Parameters

$fieldName

string

fieldName to set

$expr

mixed\salt\SqlExpr

the value

Retrieve the COUNT query

toCountQuery() : \salt\CountQuery
Inherited

Have to be overrided by child classes if needed

Exceptions

\salt\SaltException if called on BaseQuery instance

Returns

\salt\CountQuerythe SQL query for count query

Retrieve the SQL text

toSQL() : string
Inherited

Returns

stringthe memoized SQL text

Add a where clause with AND

whereAnd(string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExp $valueOrExpr) 
Inherited

Parameters

$fieldOrExpr

string\salt\SqlExpr

fieldName or SqlExpr

$operator

string

operator to use : '=', 'LIKE', 'IN', etc...

$valueOrExpr

mixed\salt\SqlExp

value or SqlExpr

Add a where clause AND EXISTS (SELECT 1 $otherQuery)

whereAndExists(\salt\Query $otherQuery, boolean $exists = TRUE
Inherited

Parameters

$otherQuery

\salt\Query

$exists

boolean

if FALSE : AND NOT EXISTS (SELECT 1 $otherQuery)

Add a WHERE clause on every object IDs (registerId)

whereAndObject(\salt\Base|array<mixed,\salt\Base> $objects) 
Inherited

Parameters

$objects

\salt\Basearray<mixed,\salt\Base>

Base object or array of Base objects. Objects have to be of the same type than the query

Add a sub query where clause : AND ( $subQuery where clauses )

whereAndQuery(\salt\Query $subQuery) 
Inherited

Parameters

$subQuery

\salt\Query

have to be a query retrieved by getSubQuery()

Add a where clause with OR

whereOr(string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExp $valueOrExpr) 
Inherited

Parameters

$fieldOrExpr

string\salt\SqlExpr

fieldName or SqlExpr

$operator

string

operator to use : '=', 'LIKE', 'IN', etc...

$valueOrExpr

mixed\salt\SqlExp

value or SqlExpr

Add a where clause OR EXISTS (SELECT 1 $otherQuery)

whereOrExists(\salt\Query $otherQuery, boolean $exists = TRUE
Inherited

Parameters

$otherQuery

\salt\Query

$exists

boolean

if FALSE : OR NOT EXISTS (SELECT 1 $otherQuery)

Add a WHERE clause on every object IDs (registerId)

whereOrObject(\salt\Base|array<mixed,\salt\Base> $objects) 
Inherited

Parameters

$objects

\salt\Basearray<mixed,\salt\Base>

Base object or array of Base objects. Objects have to be of the same type than the query

Add a sub query where clause : OR ( $subQuery where clauses )

whereOrQuery(\salt\Query $subQuery) 
Inherited

Parameters

$subQuery

\salt\Query

have to be a query retrieved by getSubQuery()

Add a bind

addBind(mixed $value, integer $type, string $source = \salt\ClauseType::ALL) : string
Inherited

Parameters

$value

mixed

value of bind

$type

integer

(FieldType) type of the field

$source

string

(Optional) ClauseType or other text : clause where the bind will be used, if we know it

Returns

stringthe bind name

get the SQL text for GROUP BY part

buildGroupClause() : string
Inherited

Returns

stringSQL text for GROUP BY part

get the SQL text for JOIN part

buildJoinClause() : string
Inherited

Returns

stringSQL text query with JOIN part

get the SQL text for ORDER BY part

buildOrderClause() : string
Inherited

Returns

stringSQL text for ORDER BY part

{@inheritDoc}

buildSQL() 
see
inherited_from \salt\UpdateQuery::buildSQL()

Build the SQL text that using the binds

buildSQL() : string
Inherited

Returns

stringthe SQL text

get the SQL text for the SELECT clause

buildSelectClause() : string
Inherited

Returns

stringSQL text of all retrieved fields

get the SQL text for WHERE part

buildWhereClause() : string
Inherited

Returns

stringSQL text query with WHERE part

Link another SqlBindField to this bindFields.

linkBindsOf(\salt\SqlBindField $other, string $source = \salt\ClauseType::ALL, string $otherSource = \salt\ClauseType::ALL
Inherited

Parameters

$other

\salt\SqlBindField

the other SqlBindField to link

$source

string

clause usage of the SqlBindField if we known it

$otherSource

string

restrict link to this source in $other

Exceptions

\salt\SaltException if this SqlBindField is already resolved

Remove binds (local and linked) of the specified source.

removeBinds(string $source) 
Inherited

Parameters

$source

string

ClauseType of specific text

Used for replace something that can be a value by a bind or a SQL text

resolveFieldName(string $source, mixed|\salt\SqlExpr $fieldNameOrValue, mixed|\salt\SqlExpr $fieldOfValue = NULL) : string | array<mixed,string>
Inherited

Parameters

$source

string

caller of resolve : ClauseType or specific text

$fieldNameOrValue

mixed\salt\SqlExpr

a FieldName (string) or SqlExpr or potential value (int, string, array) if 3rd argument is provided

$fieldOfValue

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

Returns

stringarray<mixed,string>absolute field name (alias.fieldname) or string with bind values or array of bind values if 2nd argument is an array of values

get the table name for the query

resolveTable() : string
Inherited

Returns

stringtable name, with or without alias (depends on noAlias)

get the SQL text for FROM, JOIN, WHERE, GROUP BY parts

toBaseSQL() : string
Inherited

Returns

stringSQL text query with common parts only

Add a join clause

addJoin(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr, string $type = 'INNER', string $table, boolean $withOtherDatas = TRUE
Inherited

Parameters

$other

\salt\Query

the other query to join with

$fieldOrExpr

string\salt\SqlExpr

field of ON clause

$operator

string

operator of ON clause

$valueOrExpr

mixed\salt\SqlExpr

value of ON clause

$type

string

type of join: 'INNER', 'OUTER', etc...

$table

string

object to join with : table name or subquery, with alias

$withOtherDatas

boolean

TRUE if we have to add fields, where, group by, order clause to main query

Exceptions

\salt\SaltException if this join already exists

add an ON clause to an existing join

addJoinOn(string $type, \salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr) 
Inherited

Parameters

$type

string

AND|OR

$other

\salt\Query

the other query for retrieve the join clause

$fieldOrExpr

string\salt\SqlExpr

field of ON clause

$operator

string

operator of ON clause

$valueOrExpr

mixed\salt\SqlExpr

value of ON clause

Exceptions

\salt\SaltException if join don't exists

Add a ON clause from SQL text

addJoinOnClause(\salt\Query $other, string $type, string $onClause) 
Inherited

Parameters

$other

\salt\Query

the other query for retrieve the join clause

$type

string

type of ON clause : AND|OR

$onClause

string

ON clause

add an query to an ON clause of an existing join

addJoinOnQuery(string $type, \salt\Query $other, \salt\Query $whereQuery) 
Inherited

Parameters

$type

string

AND|OR

$other

\salt\Query

the other query for retrieve the join clause

$whereQuery

\salt\Query

the query to add in ON clause

Add a where clause

addWhere(string $addType, string|\salt\SqlExpr $fieldOrExpr, string $operator, string|\salt\SqlExpr $valueOrExpr) 
Inherited

Parameters

$addType

string

AND|OR

$fieldOrExpr

string\salt\SqlExpr

fieldName or SqlExpr

$operator

string

operator to use : '=', 'LIKE', 'IN', etc...

$valueOrExpr

string\salt\SqlExpr

value or SqlExpr

Add a where clause from SQL text

addWhereClause(string $type, string $whereClause) 
Inherited

Parameters

$type

string

type of where clause : AND|OR

$whereClause

string

where clause

Add a where clause EXISTS (SELECT 1 $otherQuery)

addWhereExists(string $type, \salt\Query $otherQuery, boolean $exists = TRUE
Inherited

Parameters

$type

string

AND|OR

$otherQuery

\salt\Query

$exists

boolean

if FALSE : NOT EXISTS (SELECT 1 $otherQuery)

Add a WHERE clause on every object IDs (registerId)

addWhereObject(string $type, \salt\Base|array<mixed,\salt\Base> $objects) 
Inherited

Parameters

$type

string

AND|OR

$objects

\salt\Basearray<mixed,\salt\Base>

Base object or array of Base objects. Objects have to be of the same type than the query

Add a sub query where clause : OR ( $subQuery where clauses )

addWhereQuery(string $type, \salt\Query $subQuery) 
Inherited

Parameters

$type

string

OR|AND

$subQuery

\salt\Query

have to be a query retrieved by getSubQuery()

Throw an exception if called after SqlBind have been resolved

checkNotResolved() 
Inherited

Exceptions

\salt\SaltException if called after toSQL()

Get the type of the field

getFieldType(string $field) : integer
Inherited

Parameters

$field

string

the fieldName

Returns

integerFiedType type of the field

 Properties

 

alias for the table

$_salt_alias : string

Default

NULL
 

TRUE for allow and empty WHERE clause

$_salt_allowEmptyWhere : boolean

Default

FALSE
 

TRUE for allow WHERE clause to update multiple objects

$_salt_allowMultiple : boolean

Default

FALSE
 

database to use in table prefix

$_salt_database : string

Default

NULL
 

list of fields to retrieve (SELECT)

$_salt_fields : array<mixed,mixed>

Default

array()
content array of array(SqlExpr, alias)
 

: list of field name for group by clause

$_salt_groups : array<mixed,string>

Default

array()
 

list of join clause

$_salt_joins : array<mixed,mixed>

Default

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
		)
 

TRUE if table name does not have to use alias (DELETE query)

$_salt_noAlias : boolean

Default

FALSE
 

the object the query is build for

$_salt_obj : \salt\Base

Default

 

: list of order by clause

$_salt_orders : array<mixed,string>

Default

array()
content field ASC|DESC
 

table alias unique number

$_salt_tableAliasNumber : integer

Default

0
Static
 

list of where clause

$_salt_wheres : array<mixed,string>

Default

array()
content AND / OR are parts of $where elements
 

bind unique number

$_salt_bindNumber : integer

Default

0
Static
 

bind pagination unique number

$_salt_bindPaginationNumber : integer

Default

0
Static
 

list of binds

$_salt_binds : array<mixed,mixed>

Default

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)
			)
 

FALSE for never execute the query

$_salt_enabled : boolean

Default

TRUE
 

List of deleted objects

$_salt_objects : array<mixed,\salt\Base>

Default

 

list of linked binds

$_salt_others : array<mixed,\salt\SqlBindField[][]>

Default

array()
content
array of (ClauseType (source) => array of ClauseType(dest) => array of SqlBindField)
 

TRUE if binds values are private (do not display in debug queries)

$_salt_privateBinds : boolean

Default

FALSE
 

list of fields => values to update

$_salt_sets : array<mixed,mixed>

Default

array()
 

list of local binds by source

$_salt_sources : array<mixed,string[]>

Default

array()
content
array of (ClauseType => array of bindName)
 

SQL text that use the binds

$_salt_text : string

Default

NULL