Elgg  Version 7.1
Public Member Functions | 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

 __construct (protected readonly Connection $backup_connection)
 Initializes a new QueryBuilder. More...
 
 getConnection ()
 Returns the connection. More...
 
 subquery (string $table, ?string $alias=null)
 Creates a new SelectQueryBuilder for join/where sub queries using the DB connection of the primary QueryBuilder. More...
 
 addClause (Clause $clause, ?string $alias=null)
 Apply clause to this instance. More...
 
 prefix (string $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, string $type=ELGG_VALUE_STRING, ?string $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)
 Execute the database query for this QueryBuilder. More...
 
 executeStatement ()
 {} More...
 
 from (string $table, ?string $alias=null)
 {} More...
 
 insert (string $table)
 {} More...
 
 update (string $table)
 {} More...
 
 delete (string $table)
 {} More...
 
 join (string $fromAlias, string $join, string $alias, ?string $condition=null)
 {} More...
 
 innerJoin (string $fromAlias, string $join, string $alias, ?string $condition=null)
 {} More...
 
 leftJoin (string $fromAlias, string $join, string $alias, ?string $condition=null)
 {} More...
 
 rightJoin (string $fromAlias, string $join, string $alias, ?string $condition=null)
 {} More...
 
 orderBy (string $sort, ?string $order=null)
 {} More...
 
 addOrderBy (string $sort, ?string $order=null)
 {} More...
 
 merge ($parts=null, $boolean='AND')
 Merges multiple composite expressions with a boolean. More...
 
 compare (string $x, string $comparison, $y=null, ?string $type=null, ?bool $case_sensitive=null)
 Build value comparison clause. More...
 
 between (string $x, $lower=null, $upper=null, ?string $type=null)
 Build a between clause. More...
 
 getNextJoinAlias ()
 Get an index of the next available join alias. More...
 
 joinEntitiesTable (string $from_alias='', string $from_column='guid', ?string $join_type='inner', ?string $joined_alias=null)
 Join entity table from alias and return joined table alias. More...
 
 joinMetadataTable (string $from_alias='', string $from_column='guid', $name=null, ?string $join_type='inner', ?string $joined_alias=null)
 Join metadata table from alias and return joined table alias. More...
 
 joinAnnotationTable (string $from_alias='', string $from_column='guid', $name=null, ?string $join_type='inner', ?string $joined_alias=null)
 Join annotations table from alias and return joined table alias. More...
 
 joinRelationshipTable (string $from_alias='', string $from_column='guid', $name=null, bool $inverse=false, ?string $join_type='inner', ?string $joined_alias=null)
 Join relationship table from alias and return joined table alias. More...
 

Public Attributes

const CALCULATIONS
 

Protected Attributes

array $joins = []
 
int $join_index = 0
 
string $table_name = null
 
string $table_alias = null
 

Detailed Description

Database abstraction query builder.

Definition at line 21 of file QueryBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

Elgg\Database\QueryBuilder::__construct ( protected readonly Connection  $backup_connection)

Initializes a new QueryBuilder.

Parameters
Connection$backup_connectionConnection used for this query

Definition at line 46 of file QueryBuilder.php.

Member Function Documentation

◆ addClause()

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

Apply clause to this instance.

Parameters
Clause$clauseClause
string | null$aliasTable alias
Returns
static

Definition at line 84 of file QueryBuilder.php.

◆ addOrderBy()

Elgg\Database\QueryBuilder::addOrderBy ( string  $sort,
?string  $order = null 
)

{}

Definition at line 319 of file QueryBuilder.php.

◆ between()

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

Build a between clause.

Parameters
string$xComparison value (e.g. prefixed column name)
mixed$lowerLower bound
mixed$upperUpper bound
null | string$typeValue type for sanitization/casting
Returns
CompositeExpression|null|string

Definition at line 401 of file QueryBuilder.php.

◆ compare()

Elgg\Database\QueryBuilder::compare ( string  $x,
string  $comparison,
  $y = null,
?string  $type = null,
?bool  $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, whereas with NOT LIKE will return results where none of the criteria are met
null | string$typeValue type for sanitization/casting
null | bool$case_sensitiveUse case-sensitive comparison for strings
Returns
CompositeExpression|null|string

Definition at line 387 of file QueryBuilder.php.

◆ delete()

Elgg\Database\QueryBuilder::delete ( string  $table)

{}

Definition at line 271 of file QueryBuilder.php.

◆ execute()

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

Execute the database query for this QueryBuilder.

Parameters
bool$track_queryshould the query be tracked by timers and loggers
Returns
int|string|Result

Definition at line 205 of file QueryBuilder.php.

◆ executeStatement()

Elgg\Database\QueryBuilder::executeStatement ( )

{}

Definition at line 226 of file QueryBuilder.php.

◆ from()

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

{}

Definition at line 237 of file QueryBuilder.php.

◆ getConnection()

Elgg\Database\QueryBuilder::getConnection ( )

Returns the connection.

Need to do it this way because DBAL Query Builder does not expose the connection in 4.x

Returns
Connection
Since
6.0

Definition at line 57 of file QueryBuilder.php.

◆ getNextJoinAlias()

Elgg\Database\QueryBuilder::getNextJoinAlias ( )

Get an index of the next available join alias.

Returns
string

Definition at line 419 of file QueryBuilder.php.

◆ getTableAlias()

Elgg\Database\QueryBuilder::getTableAlias ( )

Returns the alias of the primary table.

Returns
null|string

Definition at line 131 of file QueryBuilder.php.

◆ getTableName()

Elgg\Database\QueryBuilder::getTableName ( )

Returns the name of the primary table.

Returns
string

Definition at line 122 of file QueryBuilder.php.

◆ innerJoin()

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

{}

Definition at line 287 of file QueryBuilder.php.

◆ insert()

Elgg\Database\QueryBuilder::insert ( string  $table)

{}

Definition at line 249 of file QueryBuilder.php.

◆ join()

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

{}

Definition at line 280 of file QueryBuilder.php.

◆ joinAnnotationTable()

Elgg\Database\QueryBuilder::joinAnnotationTable ( string  $from_alias = '',
string  $from_column = 'guid',
  $name = null,
?string  $join_type = 'inner',
?string  $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[]$nameAnnotation name
string | null$join_typeJOIN type
string | null$joined_aliasJoined table alias
Returns
string

Definition at line 524 of file QueryBuilder.php.

◆ joinEntitiesTable()

Elgg\Database\QueryBuilder::joinEntitiesTable ( string  $from_alias = '',
string  $from_column = 'guid',
?string  $join_type = 'inner',
?string  $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 | null$join_typeJOIN type
string | null$joined_aliasJoined table alias
Returns
string

Definition at line 435 of file QueryBuilder.php.

◆ joinMetadataTable()

Elgg\Database\QueryBuilder::joinMetadataTable ( string  $from_alias = '',
string  $from_column = 'guid',
  $name = null,
?string  $join_type = 'inner',
?string  $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[]$nameMetadata name(s)
string | null$join_typeJOIN type
string | null$joined_aliasJoined table alias
Returns
string

Definition at line 477 of file QueryBuilder.php.

◆ joinRelationshipTable()

Elgg\Database\QueryBuilder::joinRelationshipTable ( string  $from_alias = '',
string  $from_column = 'guid',
  $name = null,
bool  $inverse = false,
?string  $join_type = 'inner',
?string  $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 | null$join_typeJOIN type
string | null$joined_aliasJoined table alias
Returns
string

Definition at line 572 of file QueryBuilder.php.

◆ leftJoin()

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

{}

Definition at line 294 of file QueryBuilder.php.

◆ merge()

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|null

Definition at line 335 of file QueryBuilder.php.

◆ orderBy()

Elgg\Database\QueryBuilder::orderBy ( string  $sort,
?string  $order = null 
)

{}

Definition at line 308 of file QueryBuilder.php.

◆ param()

Elgg\Database\QueryBuilder::param (   $value,
string  $type = ELGG_VALUE_STRING,
?string  $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 | null$keyParameter key/index
Returns
string

Definition at line 145 of file QueryBuilder.php.

◆ prefix()

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

Prefixes the table name with installation DB prefix.

Parameters
string$tablethe table to prefix
Returns
string

Definition at line 104 of file QueryBuilder.php.

◆ rightJoin()

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

{}

Definition at line 301 of file QueryBuilder.php.

◆ subquery()

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

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

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

Definition at line 69 of file QueryBuilder.php.

◆ update()

Elgg\Database\QueryBuilder::update ( string  $table)

{}

Definition at line 260 of file QueryBuilder.php.

Member Data Documentation

◆ $join_index

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

Definition at line 35 of file QueryBuilder.php.

◆ $joins

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

Definition at line 33 of file QueryBuilder.php.

◆ $table_alias

string Elgg\Database\QueryBuilder::$table_alias = null
protected

Definition at line 39 of file QueryBuilder.php.

◆ $table_name

string Elgg\Database\QueryBuilder::$table_name = null
protected

Definition at line 37 of file QueryBuilder.php.

◆ CALCULATIONS

const Elgg\Database\QueryBuilder::CALCULATIONS
Initial value:
= [
'avg',
'count',
'greatest',
'least',
'max',
'min',
'sum',
]

Definition at line 23 of file QueryBuilder.php.


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