SqlSelectRequest
extends AbstractSqlRequest
in package
implements
Iterator
Uses
FieldListFacet, WhereFacet
The main SQL Select Request class
This class handles sql SELECT request to the DBMS server.
Table of Contents
Interfaces
- Iterator
Properties
- $class : string|null
- The class
- $currentIndex : int
- The current index
- $currentRow : mixed
- The current row
- $fetchIsObject : bool
- The current fetch is expecting an object
- $fetchLastStatement : PDOStatement|null
- The current fetch statement
- $filters : array<string|int, callable>
- The filter list
- $idField : string
- The ID field
- $parameters : array<string|int, string>
- The SQL Query Parameters
- $sqlAdapter : AbstractSqlAdapter
- The SQL Adapter
- $usingCache : bool
- Is using cache for results
Methods
- __construct() : mixed
- Constructor
- __toString() : string
- Get object as string
- addField() : $this
- Add a field to the field list
- alias() : mixed|$this
- asArray() : $this
- Set the output to be an array
- asArrayList() : $this
- Set the output to be a list of array
- asObject() : $this
- Set the output to be an object
- asObjectList() : $this
- Set the output to be a list of object
- count() : int
- Count the number of result of this query
- current() : mixed
- {@inheritDoc}
- disableCache() : $this
- Disable the class objects' cache
- distinct() : mixed|$this
- escapeIdentifier() : string
- Escape an SQL identifier using SQL Adapter
- escapeValue() : string
- Escape an SQL value using SQL Adapter
- exists() : bool
- Test if the query has any result
- fetch() : PermanentEntity|mixed|null
- Fetch the next result of this query
- fields() : mixed|$this
- Set/Get the field list to get
- filter() : $this
- Filter results using callable, the callable must return a boolean
- formatCondition() : string
- from() : static|string
- Set/Get the table parameter
- fromOffset() : mixed|$this
- Set/Get the offset from which we are getting results
- getClone() : static
- Get a clone of current request
- getEntityName() : string
- Get the name to use in SQL Query
- getIdField() : string
- get the ID field
- getQuery() : string
- Get the query as string
- getSqlAdapter() : AbstractSqlAdapter
- Get the SQL Adapter
- groupBy() : mixed|SqlSelectRequest
- Set/Get the group by filter
- having() : array<string|int, mixed>|static
- Set/Get the having condition
- isRowPassingFilters() : bool
- join() : $this
- Add a join condition to this query
- key() : int
- {@inheritDoc}
- maxRows() : mixed|SqlSelectRequest
- Set/Get the number of expected result (as limit)
- next() : void
- {@inheritDoc}
- number() : mixed|SqlSelectRequest
- Set/Get the number of expected result (as limit)
- orderBy() : mixed|static
- Set/Get the order by filter
- output() : mixed
- Set/Get the output parameter
- rewind() : void
- {@inheritDoc}
- run() : mixed
- Run the query and return results
- setAlias() : string
- setSqlAdapter() : static
- Set the SQL Adapter
- setUsingCache() : $this
- Set the class objects is using cache when getting results
- valid() : bool
- {@inheritDoc}
- where() : static
- Set the where clause
- formatObject() : PermanentEntity|null
- get() : mixed
- Get a parameter for this query
- set() : static
- Set a parameter for this query
- sget() : mixed
- Set/Get a parameter for this query If there is a value (non-null), we set it, or we get it
- startFetching() : void
Properties
$class
The class
protected
string|null
$class
$currentIndex
The current index
protected
int
$currentIndex
= -1
$currentRow
The current row
protected
mixed
$currentRow
= null
$fetchIsObject
The current fetch is expecting an object
protected
bool
$fetchIsObject
= false
$fetchLastStatement
The current fetch statement
protected
PDOStatement|null
$fetchLastStatement
= null
$filters
The filter list
protected
array<string|int, callable>
$filters
= []
$idField
The ID field
protected
string
$idField
$parameters
The SQL Query Parameters
protected
array<string|int, string>
$parameters
= []
$sqlAdapter
The SQL Adapter
protected
AbstractSqlAdapter
$sqlAdapter
$usingCache
Is using cache for results
protected
bool
$usingCache
= true
Methods
__construct()
Constructor
public
__construct(AbstractSqlAdapter $sqlAdapter, string $idField[, string|null $class = null ]) : mixed
Parameters
- $sqlAdapter : AbstractSqlAdapter
- $idField : string
- $class : string|null = null
__toString()
Get object as string
public
__toString() : string
Tags
Return values
stringaddField()
Add a field to the field list
public
addField(string $field) : $this
Parameters
- $field : string
Return values
$this —The current field list must be a string
alias()
public
alias([string|null $alias = null ]) : mixed|$this
Parameters
- $alias : string|null = null
Return values
mixed|$thisasArray()
Set the output to be an array
public
asArray() : $this
Return values
$thisasArrayList()
Set the output to be a list of array
public
asArrayList() : $this
Return values
$thisasObject()
Set the output to be an object
public
asObject() : $this
Return values
$thisasObjectList()
Set the output to be a list of object
public
asObjectList() : $this
Return values
$thiscount()
Count the number of result of this query
public
count([int|null $max = null ]) : int
Parameters
- $max : int|null = null
Return values
intcurrent()
{@inheritDoc}
public
current() : mixed
Tags
disableCache()
Disable the class objects' cache
public
disableCache() : $this
Tags
Return values
$thisdistinct()
public
distinct([bool|null $isDistinct = null ]) : mixed|$this
Parameters
- $isDistinct : bool|null = null
Return values
mixed|$thisescapeIdentifier()
Escape an SQL identifier using SQL Adapter
public
escapeIdentifier(string $identifier) : string
Parameters
- $identifier : string
Return values
stringescapeValue()
Escape an SQL value using SQL Adapter
public
escapeValue(mixed $value) : string
Parameters
- $value : mixed
Return values
stringexists()
Test if the query has any result
public
exists() : bool
Tags
Return values
boolfetch()
Fetch the next result of this query
public
fetch() : PermanentEntity|mixed|null
Return values
PermanentEntity|mixed|null —Query one time the DBMS and fetch result for next calls This feature is made for common used else it may have an unexpected behavior
fields()
Set/Get the field list to get
public
fields([array<string|int, mixed>|null $fields = null ]) : mixed|$this
Parameters
- $fields : array<string|int, mixed>|null = null
-
List of fields and values
Return values
mixed|$thisfilter()
Filter results using callable, the callable must return a boolean
public
filter(callable $filter) : $this
Parameters
- $filter : callable
Return values
$thisformatCondition()
public
formatCondition(array<string|int, mixed>|string $condition, string|mixed|null $operator, mixed|null $value[, bool $escapeValue = true ]) : string
Parameters
- $condition : array<string|int, mixed>|string
-
The condition or the field
- $operator : string|mixed|null
-
Value or operator
- $value : mixed|null
-
The value to use
- $escapeValue : bool = true
-
Should the value be escaped ?
Return values
stringfrom()
Set/Get the table parameter
public
from([string|null $table = null ]) : static|string
Parameters
- $table : string|null = null
Return values
static|stringfromOffset()
Set/Get the offset from which we are getting results
public
fromOffset([int|null $offset = null ]) : mixed|$this
Parameters
- $offset : int|null = null
Return values
mixed|$thisgetClone()
Get a clone of current request
public
getClone([bool $withParameters = true ]) : static
Parameters
- $withParameters : bool = true
-
True to also copy parameters, default to true
Return values
staticgetEntityName()
Get the name to use in SQL Query
public
getEntityName() : string
Return values
stringgetIdField()
get the ID field
public
getIdField() : string
Return values
stringgetQuery()
Get the query as string
public
getQuery() : string
Return values
stringgetSqlAdapter()
Get the SQL Adapter
public
getSqlAdapter() : AbstractSqlAdapter
Return values
AbstractSqlAdaptergroupBy()
Set/Get the group by filter
public
groupBy([string|null $field = null ]) : mixed|SqlSelectRequest
Parameters
- $field : string|null = null
Return values
mixed|SqlSelectRequesthaving()
Set/Get the having condition
public
having([array<string|int, mixed>|string|null $condition = null ]) : array<string|int, mixed>|static
Parameters
- $condition : array<string|int, mixed>|string|null = null
Return values
array<string|int, mixed>|staticisRowPassingFilters()
public
isRowPassingFilters(PermanentEntity|array<string|int, mixed>|scalar $row) : bool
Parameters
- $row : PermanentEntity|array<string|int, mixed>|scalar
Return values
booljoin()
Add a join condition to this query
public
join(string $entityClass[, string|null &$alias = null ][, string|null $byMyField = null ][, string|null $byTheirField = null ][, bool $mandatory = false ]) : $this
Parameters
- $entityClass : string
- $alias : string|null = null
- $byMyField : string|null = null
- $byTheirField : string|null = null
- $mandatory : bool = false
Tags
Return values
$thiskey()
{@inheritDoc}
public
key() : int
Tags
Return values
intmaxRows()
Set/Get the number of expected result (as limit)
public
maxRows([int|null $number = null ]) : mixed|SqlSelectRequest
Parameters
- $number : int|null = null
Return values
mixed|SqlSelectRequestnext()
{@inheritDoc}
public
next() : void
Tags
number()
Set/Get the number of expected result (as limit)
public
number([int|null $number = null ]) : mixed|SqlSelectRequest
Parameters
- $number : int|null = null
Return values
mixed|SqlSelectRequestorderBy()
Set/Get the order by filter
public
orderBy([string|null $fields = null ]) : mixed|static
Parameters
- $fields : string|null = null
Return values
mixed|staticoutput()
Set/Get the output parameter
public
output([string|null $output = null ]) : mixed
Parameters
- $output : string|null = null
rewind()
{@inheritDoc}
public
rewind() : void
Tags
run()
Run the query and return results
public
run() : mixed
setAlias()
public
setAlias(string $alias[, bool $defaultOnly = false ]) : string
Parameters
- $alias : string
- $defaultOnly : bool = false
Return values
stringsetSqlAdapter()
Set the SQL Adapter
public
setSqlAdapter(AbstractSqlAdapter $sqlAdapter) : static
Parameters
- $sqlAdapter : AbstractSqlAdapter
Return values
staticsetUsingCache()
Set the class objects is using cache when getting results
public
setUsingCache(bool $usingCache) : $this
Parameters
- $usingCache : bool
Return values
$thisvalid()
{@inheritDoc}
public
valid() : bool
Tags
Return values
boolwhere()
Set the where clause
public
where(array<string|int, mixed>|string $condition[, string|null $operator = null ][, string|null $value = null ][, bool $escapeValue = true ]) : static
If only $condition is provided, this is used as complete string, e.g. where("id = 5") If $equality & $value are provided, it uses it with $condition as a field (identifier), e.g. where('id', '=', '5') where identifier and value are escaped with escapeIdentifier() & escapeValue() If $equality is provided but $value is not, $equality is the value and where are using a smart comparator, e.g. where('id', '5') All examples return the same results. Smart comparator is IN for array values and = for all others.
Parameters
- $condition : array<string|int, mixed>|string
- $operator : string|null = null
- $value : string|null = null
- $escapeValue : bool = true
Return values
staticformatObject()
protected
formatObject(array<string|int, mixed> $row) : PermanentEntity|null
Parameters
- $row : array<string|int, mixed>
Return values
PermanentEntity|nullget()
Get a parameter for this query
protected
get(string $parameter[, mixed $default = null ]) : mixed
Parameters
- $parameter : string
- $default : mixed = null
set()
Set a parameter for this query
protected
set(string $parameter, mixed $value) : static
Parameters
- $parameter : string
- $value : mixed
Return values
staticsget()
Set/Get a parameter for this query If there is a value (non-null), we set it, or we get it
protected
sget(string $parameter[, mixed $value = null ]) : mixed
Parameters
- $parameter : string
- $value : mixed = null
Tags
startFetching()
protected
startFetching() : void