com\setasign\SetaFramework\Database\Query

Select Class Query Select

File: /SetaFramework/src/Database/Query/Select.php

Class hierarchy

Implements

Summary

Properties

$parts

protected array AbstractQuery::$parts = array()

Contains the single parts of the statement


Methods

__construct()

Constructor

Parameters
$columns : string|array|\com\setasign\SetaFramework\Database\ExpressionInterface
 

addFilter()

protected AbstractQuery::addFilter (
array &$part,
string $logic,
string|\Closure $statementOrColumn,
?string $operator = null,
mixed $compareValue = null
): static

Add a filter to a specific part

$statementOrColumn can be a Closure if $operator isn't set. The Closure will be called with (AbstractQuery $query, Database $quoteInterface) and has no return. $query won't be inserted directly, only the added parts of type $part will be used and set in parentheses.

Parameters
$part : array
 
$logic : string

Logic operator like "OR" or "AND" or "XOR", not important if this is the first element of a part

$statementOrColumn : string|\Closure
 
$operator : ?string
 
$compareValue : mixed

By default, this will be quoted as a value.

addOn()

protected AbstractQuery::addOn (
string $logic,
string|\Closure $statementOrColumn,
?string $operator = null,
mixed $compareValue = null
): static

Adds a on-block to last added join

Parameters
$logic : string

Logic operator like "OR" or "AND", not important if this is the first element of a part

$statementOrColumn : string|\Closure
 
$operator : ?string
 
$compareValue : mixed
 
Exceptions

Throws \BadMethodCallException

distinct()

public Select::distinct (
bool $distinct = true
): static
Parameters
$distinct : bool
 

forShare()

public Select::forShare (
void
): static

forShareNoWait()

public Select::forShareNoWait (
void
): static

forUpdate()

public Select::forUpdate (
void
): static

forUpdateNoWait()

public Select::forUpdateNoWait (
void
): static

from()

public Select::from (
string|array|true ...$tables
): static

Add selected table(s)

The method has no defined count of max arguments. Every param means one table to select from:

If a param is not an array it's simply the tablename without an alias

If a param is an array, the first entry will be the table and second the alias. The first entry can be a string, a Select-Object or a Closure (params: Database\Select $select, QuoteInterface $quoteInterface). The second entry need to be a string. Remember: When you use a Select-Object or Closure your Database need to support subqueries.

Normally the tables will be merged to all existing from-tables except the last param is an boolean TRUE.

Parameters
$tables : string|array|true
 

getPart()

public AbstractQuery::getPart (
string $part
): ?mixed

Returns the defined part

Parameters
$part : string
 

getSql()

Returns the query as string

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlColumns()

Parses content of select-part

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlFrom()

Parses the from-block to string

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlGroupBy()

Parses content of group-by part

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlHaving()

Parses content of having-part

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlJoin()

Parses the join block to string

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlLimit()

Parses the limit block to string

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlLock()

protected Select::getSqlLock (
void
): string

getSqlOrderBy()

Parses the orderBy block to string

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlWhere()

Parses the where block to string

Parameters
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 

getSqlWith()

groupBy()

public Select::groupBy (
string|array $columns
): static

Adds group-by column(s)

The column(s) will be merged to all existing group-by columns

Parameters
$columns : string|array
 

hasPart()

public AbstractQuery::hasPart (
string $part
): bool
Parameters
$part : string
 

having()

public Select::having (
string|\Closure $statementOrColumn,
?string $operator = null,
mixed $compareValue = null
): static

Adds a HAVING-AND-condition to query

Parameters
$statementOrColumn : string|\Closure
 
$operator : ?string
 
$compareValue : mixed

By default, this will be quoted as a value.

havingOr()

public Select::havingOr (
string|\Closure $statementOrColumn,
?string $operator = null,
mixed $compareValue = null
): static

Adds a HAVING-OR-condition to query

Parameters
$statementOrColumn : string|\Closure
 
$operator : ?string
 
$compareValue : mixed

By default, this will be quoted as a value.

havingOrParentheseOpen()

public Select::havingOrParentheseOpen (
bool $reverse = false
): static

Starts an HAVING-OR-condition-block in parentheses

There is no autoclosing of parentheses.

Parameters
$reverse : bool

Reverse result of parenthese with prefix NOT

havingParentheseClose()

Ends the last condition-block in parentheses

havingParentheseOpen()

public Select::havingParentheseOpen (
bool $reverse = false
): static

Starts an HAVING-AND-condition-block in parentheses

There is no autoclosing of parentheses.

Parameters
$reverse : bool

Reverse result of parenthese with prefix NOT

join()

public AbstractQuery::join (
string|array|Select|\Closure $table,
string $joinType = '',
IndexHintList|IndexHintList[] $indexHintList = array ( )
): static

Adds a join to query

Parameters
$table : string|array|Select|\Closure

By default, this will be quoted as an identifier.

$joinType : string
 
$indexHintList : IndexHintList|IndexHintList[]
 

joinInner()

public AbstractQuery::joinInner (
string|array|Select|\Closure $table,
IndexHintList|IndexHintList[] $indexHintList = array ( )
): static

Adds an inner-join to query

Parameters
$table : string|array|Select|\Closure

By default, this will be quoted as an identifier.

$indexHintList : IndexHintList|IndexHintList[]
 

joinLeft()

public AbstractQuery::joinLeft (
string|array|Select|\Closure $table,
IndexHintList|IndexHintList[] $indexHintList = array ( )
): static

Adds a left-outer-join to query

Parameters
$table : string|array|Select|\Closure

By default, this will be quoted as an identifier.

$indexHintList : IndexHintList|IndexHintList[]
 

joinRight()

public AbstractQuery::joinRight (
string|array|Select|\Closure $table,
IndexHintList|IndexHintList[] $indexHintList = array ( )
): static

Adds a right-outer-join to query

Parameters
$table : string|array|Select|\Closure

By default, this will be quoted as an identifier.

$indexHintList : IndexHintList|IndexHintList[]
 

joinStraight()

public AbstractQuery::joinStraight (
string|array|Select|\Closure $table,
IndexHintList|IndexHintList[] $indexHintList = array ( )
): static

Adds a straight-join to query

Parameters
$table : string|array|Select|\Closure

By default, this will be quoted as an identifier.

$indexHintList : IndexHintList|IndexHintList[]
 

limit()

public Select::limit (
int $limit,
?int $offset = null
): static

Sets a limit for query

Parameters
$limit : int
 
$offset : ?int
 

on()

public AbstractQuery::on (
string|array|Select|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface $statementOrColumn,
?string $operator = null,
mixed $compareValue = null
): static

Adds a ON-AND-condition to last added join

Parameters
$statementOrColumn : string|array|Select|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface

By default, this will be quoted as an identifier.

$operator : ?string
 
$compareValue : mixed

By default, this will be quoted as an identifier.

Exceptions

Throws \BadMethodCallException

onOr()

public AbstractQuery::onOr (
string|array|Select|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface $statementOrColumn,
?string $operator = null,
?string $compareValue = null
): static

Adds a ON-OR-condition to last added join

Parameters
$statementOrColumn : string|array|Select|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface

By default, this will be quoted as an identifier.

$operator : ?string
 
$compareValue : ?string

By default, this will be quoted as an identifier.

onOrParentheseOpen()

public AbstractQuery::onOrParentheseOpen (
bool $reverse = false
): static

Starts a ON-OR-condition-block in parentheses to last added join

There is no autoclosing of parentheses.

Parameters
$reverse : bool

Reverse result of parenthese with prefix NOT

onParentheseClose()

Ends the last on-condition-block in parentheses

onParentheseOpen()

public AbstractQuery::onParentheseOpen (
bool $reverse = false
): static

Starts a ON-AND-condition-block in parentheses to last added join

There is no autoclosing of parentheses.

Parameters
$reverse : bool

Reverse result of parenthese with prefix NOT

orderBy()

Adds an order-by-column to query

Parameters
$column : string|Select|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface

By default, quoted as an identifier.

$direction : string

'ASC' or 'DESC'

processFilter()

protected AbstractQuery::processFilter (
array $parts,
\com\setasign\SetaFramework\Database\QuoteInterface $quoteInterface,
string $mainPart
): string

Parses a single part to string

Parameters
$parts : array
 
$quoteInterface : \com\setasign\SetaFramework\Database\QuoteInterface
 
$mainPart : string
 
Exceptions

Throws \InvalidArgumentException

reset()

public AbstractQuery::reset (
?string $part = null
): static

Resets a single part or all parts of the statement

Parameters
$part : ?string
 

select()

public Select::select (
string|array|\com\setasign\SetaFramework\Database\ExpressionInterface $columns,
bool $overwrite = false
): static

Add selected column(s)

If this method will be called more than once the selected columns will be merged if $overwrite is false

Parameters
$columns : string|array|\com\setasign\SetaFramework\Database\ExpressionInterface
 
$overwrite : bool
 

where()

public AbstractQuery::where (
string|int|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface $statementOrColumn,
?string $operator = null,
mixed $compareValue = null
): static

Adds a WHERE-AND-condition to where part

Parameters
$statementOrColumn : string|int|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface

By default, quoted as an identifier.

$operator : ?string
 
$compareValue : mixed

By default, this will be quoted as a value.

whereOr()

public AbstractQuery::whereOr (
string|int|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface $statementOrColumn,
?string $operator = null,
mixed $compareValue = null
): static

Adds a WHERE-OR-condition to where part

Parameters
$statementOrColumn : string|int|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface

By default, quoted as an identifier.

$operator : ?string
 
$compareValue : mixed

By default, this will be quoted as a value.

whereOrParentheseOpen()

public AbstractQuery::whereOrParentheseOpen (
bool $reverse = false
): static

Starts an WHERE-OR-condition-block in parentheses

There is no autoclosing of parentheses.

Parameters
$reverse : bool

Reverse result of parenthese with prefix NOT

whereParentheseClose()

Ends the last condition-block in parentheses

whereParentheseOpen()

public AbstractQuery::whereParentheseOpen (
bool $reverse = false
): static

Starts an WHERE-AND-condition-block in parentheses

There is no autoclosing of parentheses.

Parameters
$reverse : bool

Reverse result of parenthese with prefix NOT

whereXor()

public AbstractQuery::whereXor (
string|int|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface $statementOrColumn,
?string $operator = null,
mixed $compareValue = null
): static

Adds a WHERE-XOR-condition to where part

Parameters
$statementOrColumn : string|int|\Closure|\com\setasign\SetaFramework\Database\ExpressionInterface

By default, quoted as an identifier.

$operator : ?string
 
$compareValue : mixed

By default, this will be quoted as a value.

whereXorParentheseOpen()

public AbstractQuery::whereXorParentheseOpen (
bool $reverse = false
): static

Starts an WHERE-XOR-condition-block in parentheses

There is no autoclosing of parentheses.

Parameters
$reverse : bool

Reverse result of parenthese with prefix NOT

with()

public AbstractQuery::with (
string $name,
Select|Union|\Closure|string $query
): static
Parameters
$name : string
 
$query : Select|Union|\Closure|string
 

withRecursive()

public AbstractQuery::withRecursive (
string $name,
Select|Union|\Closure|string $query
): static
Parameters
$name : string
 
$query : Select|Union|\Closure|string