SELECT Query
| package | salt\sql\queries |
|---|---|
| inherited_from | \salt\BaseQuery |
__construct(\salt\Base $obj, boolean $withField = FALSE)
| inherited_from | \salt\BaseQuery::__construct() |
|---|
\salt\Baseinstance of object for query creation
booleanTRUE for load all the fields
__construct(\salt\Base $obj)
\salt\Basethe object is used for retrieve metadata.
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
stringthe 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
stringthe field name to get
\salt\SqlExprthe SqlExpr of the fieldgetSelectFields() : array<mixed,string>
array<mixed,string>array of all fields or aliases selected by the querygetSubQuery() : \salt\Query
\salt\Querya query on the same table with the same alias for using in whereAndQuery or whereOrQuerygroupBy(string|\salt\SqlExpr $fieldOrExpr)
string\salt\SqlExprfield name to group by
initResults(\salt\Pagination $pagination= NULL, string $count= null) : \salt\DBResult
\salt\Paginationpagination object to update
stringtotal number of elements. Set on pagination
\salt\DBResultwith selected columns populatedisEmptyResults()
join(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr, string $type = 'INNER')
..
\salt\Querythe other query to join with
string\salt\SqlExprfield of ON clause
stringoperator of ON clause
mixed\salt\SqlExprvalue of ON clause
stringtype 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\Querythe other query for retrieve the join clause
string\salt\SqlExprfield of ON clause
stringoperator of ON clause
mixed\salt\SqlExprvalue of ON clause
\Exception |
if join don't exists |
|---|
joinOnAndQuery(\salt\Query $other, \salt\Query $whereQuery)
\salt\Querythe other query for retrieve the join clause
\salt\Querythe query to add in ON clause
joinOnOr(\salt\Query $other, string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExpr $valueOrExpr)
\salt\Querythe other query for retrieve the join clause
string\salt\SqlExprfield of ON clause
stringoperator of ON clause
mixed\salt\SqlExprvalue of ON clause
\Exception |
if join don't exists |
|---|
joinOnOrQuery(\salt\Query $other, \salt\Query $whereQuery)
\salt\Querythe other query for retrieve the join clause
\salt\Querythe 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\Querythe other query to join with
string\salt\SqlExprfield of ON clause
stringoperator of ON clause
mixed\salt\SqlExprvalue of ON clause
stringtype of join: 'INNER', 'OUTER', etc...
\Exception |
if this join already exists |
|---|
orderAsc(string|\salt\SqlExpr $fieldOrExpr)
string\salt\SqlExprthe field to order by ASC
orderDesc(string|\salt\SqlExpr $fieldOrExpr)
string\salt\SqlExprthe field to order by DESC
select(\salt\SqlExpr $expr, string $as = NULL)
\salt\SqlExprexpression to add in select clause, of any type
stringalias for the expression
\Exception |
|---|
selectField(string|\salt\SqlExpr $field, string $as = NULL)
string\salt\SqlExpra field name to add in select clause. A SqlExpr can also be used if it's a SqlExpr of type FIELD
stringalias if needed
selectFields(array<mixed,string> $fields)
array<mixed,string>list of fields name to add in select clause
toCountSQL() : string
Have to be overrided by child classes if needed
| inherited_from | \salt\BaseQuery::toCountSQL() |
|---|
stringSQL text of count(*) querytoCountSQL() : string
Have to be overrided by child classes if needed
\salt\SaltException |
if called |
|---|
stringthe SQL text for count querytoSQL(\salt\Pagination $pagination = NULL) : string
| inherited_from | \salt\BaseQuery::toSQL() |
|---|
\salt\Paginationpagination object for LIMIT OFFSET in query
stringSQL text of the querytoSQL(\salt\Pagination $pagination = NULL) : string
\salt\Paginationthe object for handle paging
stringthe SQL text of the query with bind placeholderswhereAnd(string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExp $valueOrExpr)
string\salt\SqlExprfieldName or SqlExpr
stringoperator to use : '=', 'LIKE', 'IN', etc...
mixed\salt\SqlExpvalue or SqlExpr
whereAndExists(\salt\Query $otherQuery, boolean $exists = TRUE)
\salt\Query
booleanif FALSE : AND NOT EXISTS (SELECT 1 $otherQuery)
whereAndObject(\salt\Base|array<mixed,\salt\Base> $objects)
\salt\Basearray<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\Queryhave to be a query retrieved by getSubQuery()
whereOr(string|\salt\SqlExpr $fieldOrExpr, string $operator, mixed|\salt\SqlExp $valueOrExpr)
string\salt\SqlExprfieldName or SqlExpr
stringoperator to use : '=', 'LIKE', 'IN', etc...
mixed\salt\SqlExpvalue or SqlExpr
whereOrExists(\salt\Query $otherQuery, boolean $exists = TRUE)
\salt\Query
booleanif FALSE : OR NOT EXISTS (SELECT 1 $otherQuery)
whereOrObject(\salt\Base|array<mixed,\salt\Base> $objects)
\salt\Basearray<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\Queryhave to be a query retrieved by getSubQuery()
addBind(mixed $value, integer $type) : string
mixedvalue of bind
integer(FieldType) type of the field
stringthe bind nameaddBindsSource(string $source, string|array<mixed,string> $binds)
stringcaller of bind (SELECT, WHERE, GROUPBY, etc...)
stringarray<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
stringSQL text query with JOIN partorderToSQL() : string
stringSQL text for ORDER BY partresolveFieldName(string $source, mixed|\salt\SqlExpr $fieldNameOrValue, mixed|\salt\SqlExpr $fieldOfValue = NULL) : string | array<mixed,string>
stringcaller of resolve : SELECT, WHERE, etc...
mixed\salt\SqlExpra FieldName (string) or SqlExpr or potential value (int, string, array) if 3rd argument is provided
mixed\salt\SqlExpra Field related to the value. Can be a SqlExpr or a string. Can be NULL if 2nd argument is a string fieldName
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 valuesresolveTable() : string
stringtable name, with or without alias (depends on noAlias)setOrRemplaceBind(string $source, mixed $value, integer $type) : string
Only work with 1 bind by source name
stringsource of bind
mixeda value for bind
integerFieldType
stringthe bind added or replacedtoBaseSQL() : string
stringSQL text query with common parts onlywheresToSQL() : string
stringSQL 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\Querythe other query to join with
string\salt\SqlExprfield of ON clause
stringoperator of ON clause
mixed\salt\SqlExprvalue of ON clause
stringtype of join: 'INNER', 'OUTER', etc...
stringobject to join with : table name of subquery
booleanTRUE 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)
stringAND|OR
\salt\Querythe other query for retrieve the join clause
string\salt\SqlExprfield of ON clause
stringoperator of ON clause
mixed\salt\SqlExprvalue of ON clause
\Exception |
if join don't exists |
|---|
addJoinOnQuery(string $type, \salt\Query $other, \salt\Query $whereQuery)
stringAND|OR
\salt\Querythe other query for retrieve the join clause
\salt\Querythe query to add in ON clause
addWhere(string $addType, string|\salt\SqlExpr $fieldOrExpr, string $operator, string|\salt\SqlExpr $valueOrExpr)
stringAND|OR
string\salt\SqlExprfieldName or SqlExpr
stringoperator to use : '=', 'LIKE', 'IN', etc...
string\salt\SqlExprvalue or SqlExpr
addWhereClause(string $type, string $whereClause)
stringtype of where clause : AND|OR
stringwhere clause
addWhereExists(string $type, \salt\Query $otherQuery, boolean $exists = TRUE)
stringAND|OR
\salt\Query
booleanif FALSE : NOT EXISTS (SELECT 1 $otherQuery)
addWhereObject(string $type, \salt\Base|array<mixed,\salt\Base> $objects)
stringAND|OR
\salt\Basearray<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)
stringOR|AND
\salt\Queryhave to be a query retrieved by getSubQuery()
getFieldType(string $field) : integer
stringthe fieldName
integerFiedType type of the field$alias : string
NULL$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 |
|---|
$tableAliasNumber : integer
0$wheres : array<mixed,string>
array()| content | AND / OR are parts of $where elements |
|---|