Elgg  Version master
Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | List of all members
Elgg\Database\QueryBuilder Class Reference

Database abstraction query builder. More...

Inheritance diagram for Elgg\Database\QueryBuilder:
Elgg\Database\Delete Elgg\Database\Insert Elgg\Database\Select Elgg\Database\Update

Public Member Functions

 subquery ($table, $alias=null)
 Creates a new SelectQueryBuilder for join/where subqueries using the DB connection of the primary QueryBuilder. More...
 
 addClause (Clause $clause, $alias=null)
 Apply clause to this instance. More...
 
 prefix ($table)
 Prefixes the table name with installation DB prefix. More...
 
 getTableName ()
 Returns the name of the primary table. More...
 
 getTableAlias ()
 Returns the alias of the primary table. More...
 
 param ($value, $type=null, $key=null)
 Sets a new parameter assigning it a unique parameter key/name if none provided Returns the name of the new parameter. More...
 
 execute (bool $track_query=true)
 
 from ($table, $alias=null)
 {} More...
 
 insert ($insert=null)
 {} More...
 
 update ($table=null, $alias=null)
 {} More...
 
 delete ($table=null, $alias=null)
 {} More...
 
 join ($fromAlias, $join, $alias, $condition=null)
 {} More...
 
 innerJoin ($fromAlias, $join, $alias, $condition=null)
 {} More...
 
 leftJoin ($fromAlias, $join, $alias, $condition=null)
 {} More...
 
 rightJoin ($fromAlias, $join, $alias, $condition=null)
 {} More...
 
 merge ($parts=null, $boolean= 'AND')
 Merges multiple composite expressions with a boolean. More...
 
 compare ($x, $comparison, $y=null, $type=null, $case_sensitive=null)
 Build value comparison clause. More...
 
 between ($x, $lower=null, $upper=null, $type=null)
 Build a between clause. More...
 
 getNextJoinAlias ()
 Get an index of the next available join alias. More...
 
 joinEntitiesTable ($from_alias= '', $from_column= 'guid', $join_type= 'inner', $joined_alias=null)
 Join entity table from alias and return joined table alias. More...
 
 joinMetadataTable ($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
 Join metadata table from alias and return joined table alias. More...
 
 joinAnnotationTable ($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
 Join annotations table from alias and return joined table alias. More...
 
 joinRelationshipTable ($from_alias= '', $from_column= 'guid', $name=null, $inverse=false, $join_type= 'inner', $joined_alias=null)
 Join relationship table from alias and return joined table alias. More...
 

Public Attributes

const TABLE_ENTITIES = 'entities'
 
const TABLE_METADATA = 'metadata'
 
const TABLE_ANNOTATIONS = 'annotations'
 
const TABLE_RELATIONSHIPS = 'entity_relationships'
 

Static Public Attributes

static $calculations
 

Protected Attributes

 $joins = []
 
 $join_index = 0
 
 $table_name
 
 $table_alias
 

Detailed Description

Database abstraction query builder.

Definition at line 18 of file QueryBuilder.php.

Member Function Documentation

Elgg\Database\QueryBuilder::addClause ( Clause  $clause,
  $alias = null 
)

Apply clause to this instance.

Parameters
Clause$clauseClause
string$aliasTable alias
Returns
static

Definition at line 78 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::between (   $x,
  $lower = null,
  $upper = null,
  $type = null 
)

Build a between clause.

Parameters
string$xComparison value (e.g. prefixed column name)
mixed$lowerLower bound
mixed$upperUpper bound
Returns
CompositeExpression|null|string

Definition at line 361 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::compare (   $x,
  $comparison,
  $y = null,
  $type = null,
  $case_sensitive = null 
)

Build value comparison clause.

Parameters
string$xComparison value (e.g. prefixed column name)
string$comparisonComparison operator
mixed$yValue to compare against If the value is an array, comparisons will be performed in such as a way as to ensure that either all or none of the elements of the array meet the criteria, e.g. in case of LIKE will return results where at least one element matches the criteria, where as with NOT LIKE will return results where none of the criteria are met
string$typeValue type for sanitization/casting
bool$case_sensitiveUse case sensitive comparison for strings
Returns
CompositeExpression|null|string

Definition at line 348 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::delete (   $table = null,
  $alias = null 
)

{}

Definition at line 254 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::execute ( bool  $track_query = true)

Parameters
bool$track_queryshould the query be tracked by timers and loggers

Definition at line 195 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::from (   $table,
  $alias = null 
)

{}

Definition at line 219 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::getNextJoinAlias ( )

Get an index of the next available join alias.

Returns
string

Definition at line 377 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::getTableAlias ( )

Returns the alias of the primary table.

Returns
string

Definition at line 123 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::getTableName ( )

Returns the name of the primary table.

Returns
string

Definition at line 115 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::innerJoin (   $fromAlias,
  $join,
  $alias,
  $condition = null 
)

{}

Definition at line 271 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::insert (   $insert = null)

{}

Definition at line 231 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::join (   $fromAlias,
  $join,
  $alias,
  $condition = null 
)

{}

Definition at line 264 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::joinAnnotationTable (   $from_alias = '',
  $from_column = 'guid',
  $name = null,
  $join_type = 'inner',
  $joined_alias = null 
)

Join annotations table from alias and return joined table alias.

Parameters
string$from_aliasMain table alias
string$from_columnGuid column name in the main table
string|string[]$name Annotation name
string$join_typeJOIN type
string$joined_aliasJoined table alias
Returns
string

Definition at line 482 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::joinEntitiesTable (   $from_alias = '',
  $from_column = 'guid',
  $join_type = 'inner',
  $joined_alias = null 
)

Join entity table from alias and return joined table alias.

Parameters
string$from_aliasMain table alias
string$from_columnGuid column name in the main table
string$join_typeJOIN type
string$joined_aliasJoined table alias
Returns
string

Definition at line 393 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::joinMetadataTable (   $from_alias = '',
  $from_column = 'guid',
  $name = null,
  $join_type = 'inner',
  $joined_alias = null 
)

Join metadata table from alias and return joined table alias.

Parameters
string$from_aliasAlias of the main table
string$from_columnGuid column name in the main table
string|string[]$name Metadata name(s)
string$join_typeJOIN type
string$joined_aliasJoined table alias
Returns
string

Definition at line 435 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::joinRelationshipTable (   $from_alias = '',
  $from_column = 'guid',
  $name = null,
  $inverse = false,
  $join_type = 'inner',
  $joined_alias = null 
)

Join relationship table from alias and return joined table alias.

Parameters
string$from_aliasMain table alias
string$from_columnGuid column name in the main table
string$nameRelationship name
bool$inverseJoin on guid_two column
string$join_typeJOIN type
string$joined_aliasJoined table alias
Returns
string

Definition at line 530 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::leftJoin (   $fromAlias,
  $join,
  $alias,
  $condition = null 
)

{}

Definition at line 278 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::merge (   $parts = null,
  $boolean = 'AND' 
)

Merges multiple composite expressions with a boolean.

Parameters
mixed$partsComposite expression(s) or string(s)
string$booleanAND|OR
Returns
CompositeExpression|string

Definition at line 297 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::param (   $value,
  $type = null,
  $key = null 
)

Sets a new parameter assigning it a unique parameter key/name if none provided Returns the name of the new parameter.

Parameters
mixed$valueParameter value
string$typeParameter type
string$keyParameter key/index
Returns
string

Definition at line 137 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::prefix (   $table)

Prefixes the table name with installation DB prefix.

Parameters
string$table
Returns
string

Definition at line 97 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::rightJoin (   $fromAlias,
  $join,
  $alias,
  $condition = null 
)

{}

Definition at line 285 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::subquery (   $table,
  $alias = null 
)

Creates a new SelectQueryBuilder for join/where subqueries using the DB connection of the primary QueryBuilder.

Parameters
string$tableMain table name
string$aliasSelect alias
Returns
Select

Definition at line 63 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::update (   $table = null,
  $alias = null 
)

{}

Definition at line 242 of file QueryBuilder.php.

Member Data Documentation

Elgg\Database\QueryBuilder::$calculations
static
Initial value:
= [
'avg',
'count',
'greatest',
'least',
'max',
'min',
'sum',
]

Definition at line 25 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::$join_index = 0
protected

Definition at line 43 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::$joins = []
protected

Definition at line 38 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::$table_alias
protected

Definition at line 53 of file QueryBuilder.php.

Elgg\Database\QueryBuilder::$table_name
protected

Definition at line 48 of file QueryBuilder.php.

const Elgg\Database\QueryBuilder::TABLE_ANNOTATIONS = 'annotations'

Definition at line 22 of file QueryBuilder.php.

const Elgg\Database\QueryBuilder::TABLE_ENTITIES = 'entities'

Definition at line 20 of file QueryBuilder.php.

const Elgg\Database\QueryBuilder::TABLE_METADATA = 'metadata'

Definition at line 21 of file QueryBuilder.php.

const Elgg\Database\QueryBuilder::TABLE_RELATIONSHIPS = 'entity_relationships'

Definition at line 23 of file QueryBuilder.php.


The documentation for this class was generated from the following file: