PHP Class Nette\Database\Table\Selection

Selection is based on the great library NotORM http://www.notorm.com written by Jakub Vrana.
Author: Jakub Vrana
Author: Jan Skrasek
Inheritance: extends Nette\Object, implements Iterator, implements ArrayAccess, implements Countable
Show file Open project: nette/database Class Usage Examples

Protected Properties

Property Type Description
$accessedColumns of touched columns
$aggregation of [conditions => [key => IRow]]; used by GroupedSelection
$cache Nette\Caching\Cache
$context Nette\Database\Context
$conventions Nette\Database\IConventions
$data modifiable data in [primary key => IRow] format
$dataRefreshed boolean
$generalCacheKey string
$globalRefCache cache array of Selection and GroupedSelection prototypes
$keys of primary key values
$name table name
$observeCache should instance observe accessed columns caching
$previousAccessedColumns of earlier touched columns
$primary primary key field name
$primarySequence primary column sequence name, FALSE for autodetection
$refCache mixed
$rows data read from database in [primary key => IRow] format
$specificCacheKey string
$sqlBuilder SqlBuilder

Public Methods

Method Description
__clone ( )
__construct ( Context $context, Nette\Database\IConventions $conventions, $tableName, Nette\Caching\IStorage $cacheStorage = NULL ) Creates filtered table representation.
__destruct ( )
accessColumn ( $key, $selectColumn = TRUE ) : boolean
aggregation ( $function ) : string Executes aggregation function.
alias ( $tableChain, $alias ) : self Aliases table. Example ':book:book_tag.tag', 'tg'
count ( $column = NULL ) : integer Counts number of rows.
createSelectionInstance ( $table = NULL )
current ( ) : Nette\Database\Table\IRow
delete ( ) : integer Deletes all rows in result set.
fetch ( )
fetchAll ( )
fetchAssoc ( $path )
fetchField ( $column = NULL ) : mixed | FALSE Fetches single field.
fetchPairs ( $key = NULL, $value = NULL )
get ( $key ) : Nette\Database\Table\IRow Returns row specified by primary key.
getDataRefreshed ( ) : boolean Returns if selection requeried for more columns.
getName ( ) : string
getPreviousAccessedColumns ( ) : array | false Loads cache of previous accessed columns and returns it.
getPrimary ( $need = TRUE ) : string | array | null
getPrimarySequence ( ) : string
getReferencedTable ( ActiveRow $row, $table, $column = NULL ) : ActiveRow | null | FALSE Returns referenced row.
getReferencingTable ( $table, $column, $active = NULL ) : GroupedSelection Returns referencing rows.
getSql ( ) : string
getSqlBuilder ( ) : SqlBuilder
group ( $columns, $params ) : self Sets group clause, more calls rewrite old value.
having ( $having, $params ) : self Sets having clause, more calls rewrite old value.
insert ( $data ) : Nette\Database\Table\IRow | integer | boolean Inserts row in a table.
joinWhere ( $tableChain, $condition, $params ) : self Adds ON condition when joining specified table, more calls appends with AND.
key ( ) : string
limit ( $limit, $offset = NULL ) : self Sets limit clause, more calls rewrite old values.
max ( $column ) : integer Returns maximum value from a column.
min ( $column ) : integer Returns minimum value from a column.
next ( )
offsetExists ( $key ) : boolean Tests if row exists.
offsetGet ( $key ) : Nette\Database\Table\IRow Returns specified row.
offsetSet ( $key, $value ) : null Mimic row.
offsetUnset ( $key ) : null Removes row from result set.
order ( $columns, $params ) : self Adds order clause, more calls appends to the end.
page ( $page, $itemsPerPage, &$numOfPages = NULL ) : self Sets offset using page number, more calls rewrite old values.
removeAccessColumn ( $key )
rewind ( ) ******************* interface Iterator ****************d*g*
select ( $columns, $params ) : self Adds select clause, more calls appends to the end.
setPrimarySequence ( $sequence ) : self
sum ( $column ) : integer Returns sum of values in a column.
update ( $data ) : integer Updates all rows in result set.
valid ( )
where ( $condition, $params ) : self Adds where condition, more calls appends with AND.
whereOr ( array $parameters ) : self Adds where condition using the OR operator between parameters.
wherePrimary ( $key ) : self Adds condition for primary key.

Protected Methods

Method Description
condition ( $condition, array $params, $tableChain = NULL ) : void Adds condition, more calls appends with AND.
createGroupedSelectionInstance ( $table, $column )
createRow ( array $row )
emptyResultSet ( $clearCache = TRUE, $deleteRererencedCache = TRUE )
execute ( ) ******************* internal ****************d*g*
getGeneralCacheKey ( ) : string Returns general cache key independent on query parameters or sql limit Used e.g. for previously accessed columns caching
getRefTable ( &$refPath ) : self Returns Selection parent for caching.
getSpecificCacheKey ( ) : string Returns object specific cache key dependent on query parameters Used e.g. for reference memory caching
loadRefCache ( ) Loads refCache references
query ( $query )
saveCacheState ( )

Method Details

__clone() public method

public __clone ( )

__construct() public method

Creates filtered table representation.
public __construct ( Context $context, Nette\Database\IConventions $conventions, $tableName, Nette\Caching\IStorage $cacheStorage = NULL )
$context Nette\Database\Context
$conventions Nette\Database\IConventions
$cacheStorage Nette\Caching\IStorage

__destruct() public method

public __destruct ( )

accessColumn() public method

public accessColumn ( $key, $selectColumn = TRUE ) : boolean
return boolean if selection requeried for more columns.

aggregation() public method

Executes aggregation function.
public aggregation ( $function ) : string
return string

alias() public method

Aliases table. Example ':book:book_tag.tag', 'tg'
public alias ( $tableChain, $alias ) : self
return self

condition() protected method

Adds condition, more calls appends with AND.
protected condition ( $condition, array $params, $tableChain = NULL ) : void
$params array
return void

count() public method

Counts number of rows.
public count ( $column = NULL ) : integer
return integer

createGroupedSelectionInstance() protected method

protected createGroupedSelectionInstance ( $table, $column )

createRow() protected method

protected createRow ( array $row )
$row array

createSelectionInstance() public method

public createSelectionInstance ( $table = NULL )

current() public method

public current ( ) : Nette\Database\Table\IRow
return Nette\Database\Table\IRow

delete() public method

Deletes all rows in result set.
public delete ( ) : integer
return integer number of affected rows

emptyResultSet() protected method

protected emptyResultSet ( $clearCache = TRUE, $deleteRererencedCache = TRUE )

execute() protected method

******************* internal ****************d*g*
protected execute ( )

fetch() public method

public fetch ( )

fetchAll() public method

public fetchAll ( )

fetchAssoc() public method

public fetchAssoc ( $path )

fetchField() public method

Fetches single field.
public fetchField ( $column = NULL ) : mixed | FALSE
return mixed | FALSE

fetchPairs() public method

public fetchPairs ( $key = NULL, $value = NULL )

get() public method

Returns row specified by primary key.
public get ( $key ) : Nette\Database\Table\IRow
return Nette\Database\Table\IRow or FALSE if there is no such row

getDataRefreshed() public method

Returns if selection requeried for more columns.
public getDataRefreshed ( ) : boolean
return boolean

getGeneralCacheKey() protected method

Returns general cache key independent on query parameters or sql limit Used e.g. for previously accessed columns caching
protected getGeneralCacheKey ( ) : string
return string

getName() public method

public getName ( ) : string
return string

getPreviousAccessedColumns() public method

Loads cache of previous accessed columns and returns it.
public getPreviousAccessedColumns ( ) : array | false
return array | false

getPrimary() public method

public getPrimary ( $need = TRUE ) : string | array | null
return string | array | null

getPrimarySequence() public method

public getPrimarySequence ( ) : string
return string

getRefTable() protected method

Returns Selection parent for caching.
protected getRefTable ( &$refPath ) : self
return self

getReferencedTable() public method

Returns referenced row.
public getReferencedTable ( ActiveRow $row, $table, $column = NULL ) : ActiveRow | null | FALSE
$row ActiveRow
return ActiveRow | null | FALSE NULL if the row does not exist, FALSE if the relationship does not exist

getReferencingTable() public method

Returns referencing rows.
public getReferencingTable ( $table, $column, $active = NULL ) : GroupedSelection
return GroupedSelection

getSpecificCacheKey() protected method

Returns object specific cache key dependent on query parameters Used e.g. for reference memory caching
protected getSpecificCacheKey ( ) : string
return string

getSql() public method

public getSql ( ) : string
return string

getSqlBuilder() public method

public getSqlBuilder ( ) : SqlBuilder
return SqlBuilder

group() public method

Sets group clause, more calls rewrite old value.
public group ( $columns, $params ) : self
return self

having() public method

Sets having clause, more calls rewrite old value.
public having ( $having, $params ) : self
return self

insert() public method

Inserts row in a table.
public insert ( $data ) : Nette\Database\Table\IRow | integer | boolean
return Nette\Database\Table\IRow | integer | boolean Returns IRow or number of affected rows for Selection or table without primary key

joinWhere() public method

Adds ON condition when joining specified table, more calls appends with AND.
public joinWhere ( $tableChain, $condition, $params ) : self
return self

key() public method

public key ( ) : string
return string row ID

limit() public method

Sets limit clause, more calls rewrite old values.
public limit ( $limit, $offset = NULL ) : self
return self

loadRefCache() protected method

Loads refCache references
protected loadRefCache ( )

max() public method

Returns maximum value from a column.
public max ( $column ) : integer
return integer

min() public method

Returns minimum value from a column.
public min ( $column ) : integer
return integer

next() public method

public next ( )

offsetExists() public method

Tests if row exists.
public offsetExists ( $key ) : boolean
return boolean

offsetGet() public method

Returns specified row.
public offsetGet ( $key ) : Nette\Database\Table\IRow
return Nette\Database\Table\IRow or NULL if there is no such row

offsetSet() public method

Mimic row.
public offsetSet ( $key, $value ) : null
return null

offsetUnset() public method

Removes row from result set.
public offsetUnset ( $key ) : null
return null

order() public method

Adds order clause, more calls appends to the end.
public order ( $columns, $params ) : self
return self

page() public method

Sets offset using page number, more calls rewrite old values.
public page ( $page, $itemsPerPage, &$numOfPages = NULL ) : self
return self

query() protected method

protected query ( $query )

removeAccessColumn() public method

public removeAccessColumn ( $key )

rewind() public method

******************* interface Iterator ****************d*g*
public rewind ( )

saveCacheState() protected method

protected saveCacheState ( )

select() public method

Adds select clause, more calls appends to the end.
public select ( $columns, $params ) : self
return self

setPrimarySequence() public method

public setPrimarySequence ( $sequence ) : self
return self

sum() public method

Returns sum of values in a column.
public sum ( $column ) : integer
return integer

update() public method

Joins in UPDATE are supported only in MySQL
public update ( $data ) : integer
return integer number of affected rows

valid() public method

public valid ( )

where() public method

Adds where condition, more calls appends with AND.
public where ( $condition, $params ) : self
return self

whereOr() public method

More calls appends with AND.
public whereOr ( array $parameters ) : self
$parameters array
return self

wherePrimary() public method

Adds condition for primary key.
public wherePrimary ( $key ) : self
return self

Property Details

$accessedColumns protected property

of touched columns
protected $accessedColumns

$aggregation protected property

of [conditions => [key => IRow]]; used by GroupedSelection
protected $aggregation

$cache protected property

protected Cache,Nette\Caching $cache
return Nette\Caching\Cache

$context protected property

protected Context,Nette\Database $context
return Nette\Database\Context

$conventions protected property

protected IConventions,Nette\Database $conventions
return Nette\Database\IConventions

$data protected property

modifiable data in [primary key => IRow] format
protected $data

$dataRefreshed protected property

protected bool $dataRefreshed
return boolean

$generalCacheKey protected property

protected string $generalCacheKey
return string

$globalRefCache protected property

cache array of Selection and GroupedSelection prototypes
protected $globalRefCache

$keys protected property

of primary key values
protected $keys

$name protected property

table name
protected $name

$observeCache protected property

should instance observe accessed columns caching
protected $observeCache

$previousAccessedColumns protected property

of earlier touched columns
protected $previousAccessedColumns

$primary protected property

primary key field name
protected $primary

$primarySequence protected property

primary column sequence name, FALSE for autodetection
protected $primarySequence

$refCache protected property

protected mixed $refCache
return mixed

$rows protected property

data read from database in [primary key => IRow] format
protected $rows

$specificCacheKey protected property

protected string $specificCacheKey
return string

$sqlBuilder protected property

protected SqlBuilder,Nette\Database\Table $sqlBuilder
return SqlBuilder