Class

eZ\Publish\Core\Persistence\Doctrine\SelectDoctrineQuery

class SelectDoctrineQuery extends AbstractDoctrineQuery implements SelectQuery

Class SelectDoctrineQuery.

Properties

Expression $expr
bool $permissionSubtreeJoinAdded Holds the state of permission subtree join, which is LEFT JOIN on 'ezcontentobjecttree' table with alias 'permissionsubtree'.

Methods

__construct(Connection $connection)

from AbstractDoctrineQuery
SelectQuery subSelect()

Create a subselect used with the current query.

from AbstractDoctrineQuery
Statement prepare()

from AbstractDoctrineQuery
string bindValue($value, $placeHolder = null, $type = PDO::PARAM_STR)

Binds the value $value to the specified variable name $placeHolder.

from AbstractDoctrineQuery
string bindParam($param, $placeHolder = null, $type = PDO::PARAM_STR)

Binds the parameter $param to the specified variable name $placeHolder..

from AbstractDoctrineQuery
string __toString()

Return the SQL string for this query.

from AbstractDoctrineQuery
SelectQuery select()

Opens the query and selects which columns you want to return with the query.

string alias(string $name, string $alias)

Returns SQL to create an alias.

SelectQuery selectDistinct()

Opens the query and uses a distinct select on the columns you want to return with the query.

SelectQuery from()

Select which tables you want to select from.

SelectQuery innerJoin()

Returns the SQL for an inner join or prepares $fromString for an inner join.

SelectQuery leftJoin()

Returns the SQL for a left join or prepares $fromString for a left join.

SelectQuery rightJoin()

Returns the SQL for a right join or prepares $fromString for a right join.

SelectQuery where()

Adds a where clause with logical expressions to the query.

SelectQuery limit(string $limit, string $offset = '')

Returns SQL that limits the result set.

SelectQuery orderBy(string $column, string $type = self::ASC)

Returns SQL that orders the result set by a given column.

SelectQuery groupBy()

Returns SQL that groups the result set by a given column.

SelectQuery having()

Returns SQL that set having by a given expression.

string getQuery()

Returns the query string for this query object.

Details

in AbstractDoctrineQuery at line 73
public __construct(Connection $connection)

Parameters

Connection $connection

in AbstractDoctrineQuery at line 84
public SelectQuery subSelect()

Create a subselect used with the current query.

Return Value

SelectQuery

in AbstractDoctrineQuery at line 92
public Statement prepare()

Return Value

Statement

in AbstractDoctrineQuery at line 146
public string bindValue($value, $placeHolder = null, $type = PDO::PARAM_STR)

Binds the value $value to the specified variable name $placeHolder.

This method provides a shortcut for PDOStatement::bindValue when using prepared statements.

The parameter $value specifies the value that you want to bind. If $placeholder is not provided bindValue() will automatically create a placeholder for you. An automatic placeholder will be of the name 'placeholder1', 'placeholder2' etc.

For more information see {@link http://php.net/pdostatement-bindparam}

Example: $value = 2; $q->eq( 'id', $q->bindValue( $value ) ); $stmt = $q->prepare(); // the value 2 is bound to the query. $value = 4; $stmt->execute(); // executed with 'id = 2'

Parameters

$value
$placeHolder
$type

Return Value

string the placeholder name used.

in AbstractDoctrineQuery at line 188
public string bindParam($param, $placeHolder = null, $type = PDO::PARAM_STR)

Binds the parameter $param to the specified variable name $placeHolder..

This method provides a shortcut for PDOStatement::bindParam when using prepared statements.

The parameter $param specifies the variable that you want to bind. If $placeholder is not provided bind() will automatically create a placeholder for you. An automatic placeholder will be of the name 'placeholder1', 'placeholder2' etc.

For more information see {@link http://php.net/pdostatement-bindparam}

Example: $value = 2; $q->eq( 'id', $q->bindParam( $value ) ); $stmt = $q->prepare(); // the parameter $value is bound to the query. $value = 4; $stmt->execute(); // executed with 'id = 4'

Parameters

$param
$placeHolder
$type

Return Value

string the placeholder name used.

See also

doBind()

in AbstractDoctrineQuery at line 206
public string __toString()

Return the SQL string for this query.

Return Value

string

at line 92
public SelectQuery select()

Opens the query and selects which columns you want to return with the query.

select() accepts an arbitrary number of parameters. Each parameter must contain either the name of a column or an array containing the names of the columns. Each call to select() appends columns to the list of columns that will be used in the query.

Example: $q->select( 'column1', 'column2' ); The same could also be written $columns[] = 'column1'; $columns[] = 'column2; $q->select( $columns ); or using several calls $q->select( 'column1' )->select( 'column2' );

Each of above code produce SQL clause 'SELECT column1, column2' for the query.

Return Value

SelectQuery returns a pointer to $this.

Exceptions

QueryException if called with no parameters..

at line 121
public string alias(string $name, string $alias)

Returns SQL to create an alias.

This method can be used to create an alias for either a table or a column. Example: // this will make the table users have the alias employees // and the column userid the alias employeeid $q->select( $q->alias( 'userid', 'employeeid' ) ->from( $q->alias( 'users', 'employees' ) );

Parameters

string $name
string $alias

Return Value

string the query string "columnname as targetname"

at line 164
public SelectQuery selectDistinct()

Opens the query and uses a distinct select on the columns you want to return with the query.

selectDistinct() accepts an arbitrary number of parameters. Each parameter must contain either the name of a column or an array containing the names of the columns. Each call to selectDistinct() appends columns to the list of columns that will be used in the query.

Example: $q->selectDistinct( 'column1', 'column2' ); The same could also be written $columns[] = 'column1'; $columns[] = 'column2; $q->selectDistinct( $columns ); or using several calls $q->selectDistinct( 'column1' )->select( 'column2' );

Each of above code produce SQL clause 'SELECT DISTINCT column1, column2' for the query.

You may call select() after calling selectDistinct() which will result in the additional columns beein added. A call of selectDistinct() after select() will result in an \eZ\Publish\Core\Persistence\Database\SelectQueryInvalidException.

Return Value

SelectQuery returns a pointer to $this.

Exceptions

QueryException if called with no parameters..

at line 193
public SelectQuery from()

Select which tables you want to select from.

from() accepts an arbitrary number of parameters. Each parameter must contain either the name of a table or an array containing the names of tables.. Each call to from() appends tables to the list of tables that will be used in the query.

Example: // the following code will produce the SQL // SELECT id FROM tablename $q->select( 'id' )->from( 'tablename' );

Return Value

SelectQuery a pointer to $this

Exceptions

QueryException if called with no parameters.

at line 258
public SelectQuery innerJoin()

Returns the SQL for an inner join or prepares $fromString for an inner join.

This method could be used in two forms:

innerJoin( 't2', $joinCondition )

Takes 2 string arguments and returns \eZ\Publish\Core\Persistence\Database\SelectQuery.

The first parameter is the name of the table to join with. The table to which is joined should have been previously set with the from() method.

The second parameter should be a string containing a join condition that is returned by an \eZ\Publish\Core\Persistence\Database\SelectQueryExpression.

Example: // the following code will produce the SQL // SELECT id FROM t1 INNER JOIN t2 ON t1.id = t2.id $q->select( 'id' )->from( 't1' )->innerJoin( 't2', $q->expr->eq('t1.id', 't2.id' ) );

innerJoin( 't2', 't1.id', 't2.id' )

Takes 3 string arguments and returns \eZ\Publish\Core\Persistence\Database\SelectQuery. This is a simplified form of the 2 parameter version. innerJoin( 't2', 't1.id', 't2.id' ) is equal to innerJoin( 't2', $this->expr->eq('t1.id', 't2.id' ) );

The first parameter is the name of the table to join with. The table to which is joined should have been previously set with the from() method.

The second parameter is the name of the column on the table set previously with the from() method and the third parameter the name of the column to join with on the table that was specified in the first parameter.

Example: // the following code will produce the SQL // SELECT id FROM t1 INNER JOIN t2 ON t1.id = t2.id $q->select( 'id' )->from( 't1' )->innerJoin( 't2', 't1.id', 't2.id' );

Return Value

SelectQuery

Exceptions

QueryException if called with inconsistent parameters or if invoked without preceding call to from().

at line 346
public SelectQuery leftJoin()

Returns the SQL for a left join or prepares $fromString for a left join.

This method could be used in two forms:

leftJoin( 't2', $joinCondition )

Takes 2 string arguments and returns \eZ\Publish\Core\Persistence\Database\SelectQuery.

The first parameter is the name of the table to join with. The table to which is joined should have been previously set with the from() method.

The second parameter should be a string containing a join condition that is returned by an \eZ\Publish\Core\Persistence\Database\SelectQueryExpression.

Example: // the following code will produce the SQL // SELECT id FROM t1 LEFT JOIN t2 ON t1.id = t2.id $q->select( 'id' )->from( 't1' )->leftJoin( 't2', $q->expr->eq('t1.id', 't2.id' ) );

leftJoin( 't2', 't1.id', 't2.id' )

Takes 3 string arguments and returns \eZ\Publish\Core\Persistence\Database\SelectQuery. This is a simplified form of the 2 parameter version. leftJoin( 't2', 't1.id', 't2.id' ) is equal to leftJoin( 't2', $this->expr->eq('t1.id', 't2.id' ) );

The first parameter is the name of the table to join with. The table to which is joined should have been previously set with the from() method.

The second parameter is the name of the column on the table set previously with the from() method and the third parameter the name of the column to join with on the table that was specified in the first parameter.

Example: // the following code will produce the SQL // SELECT id FROM t1 LEFT JOIN t2 ON t1.id = t2.id $q->select( 'id' )->from( 't1' )->leftJoin( 't2', 't1.id', 't2.id' );

Return Value

SelectQuery

Exceptions

QueryException if called with inconsistent parameters or if invoked without preceding call to from().

at line 402
public SelectQuery rightJoin()

Returns the SQL for a right join or prepares $fromString for a right join.

This method could be used in two forms:

rightJoin( 't2', $joinCondition )

Takes 2 string arguments and returns \eZ\Publish\Core\Persistence\Database\SelectQuery.

The first parameter is the name of the table to join with. The table to which is joined should have been previously set with the from() method.

The second parameter should be a string containing a join condition that is returned by an \eZ\Publish\Core\Persistence\Database\SelectQueryExpression.

Example: // the following code will produce the SQL // SELECT id FROM t1 LEFT JOIN t2 ON t1.id = t2.id $q->select( 'id' )->from( 't1' )->rightJoin( 't2', $q->expr->eq('t1.id', 't2.id' ) );

rightJoin( 't2', 't1.id', 't2.id' )

Takes 3 string arguments and returns \eZ\Publish\Core\Persistence\Database\SelectQuery. This is a simplified form of the 2 parameter version. rightJoin( 't2', 't1.id', 't2.id' ) is equal to rightJoin( 't2', $this->expr->eq('t1.id', 't2.id' ) );

The first parameter is the name of the table to join with. The table to which is joined should have been previously set with the from() method.

The second parameter is the name of the column on the table set previously with the from() method and the third parameter the name of the column to join with on the table that was specified in the first parameter.

Example: // the following code will produce the SQL // SELECT id FROM t1 LEFT JOIN t2 ON t1.id = t2.id $q->select( 'id' )->from( 't1' )->rightJoin( 't2', 't1.id', 't2.id' );

Return Value

SelectQuery

Exceptions

QueryException if called with inconsistent parameters or if invoked without preceding call to from().

at line 429
public SelectQuery where()

Adds a where clause with logical expressions to the query.

where() accepts an arbitrary number of parameters. Each parameter must contain a logical expression or an array with logical expressions. If you specify multiple logical expression they are connected using a logical and.

Multiple calls to where() will join the expressions using a logical and.

Example: $q->select( '*' )->from( 'table' )->where( $q->expr->eq( 'id', 1 ) );

Return Value

SelectQuery

Exceptions

QueryException if called with no parameters.

at line 466
public SelectQuery limit(string $limit, string $offset = '')

Returns SQL that limits the result set.

$limit controls the maximum number of rows that will be returned. $offset controls which row that will be the first in the result set from the total amount of matching rows.

Example: $q->select( '*' )->from( 'table' ) ->limit( 10, 0 );

LIMIT is not part of SQL92. It is implemented here anyway since all databases support it one way or the other and because it is essential.

Parameters

string $limit integer expression
string $offset integer expression

Return Value

SelectQuery

at line 491
public SelectQuery orderBy(string $column, string $type = self::ASC)

Returns SQL that orders the result set by a given column.

You can call orderBy multiple times. Each call will add a column to order by.

Example: $q->select( '*' )->from( 'table' ) ->orderBy( 'id' );

Parameters

string $column a column name in the result set
string $type if the column should be sorted ascending or descending. you can specify this using \eZ\Publish\Core\Persistence\Database\SelectQuery::ASC or \eZ\Publish\Core\Persistence\Database\SelectQuery::DESC

Return Value

SelectQuery a pointer to $this

at line 520
public SelectQuery groupBy()

Returns SQL that groups the result set by a given column.

You can call groupBy multiple times. Each call will add a column to group by.

Example: $q->select( '*' )->from( 'table' ) ->groupBy( 'id' );

Return Value

SelectQuery a pointer to $this

Exceptions

QueryException if called with no parameters.

at line 551
public SelectQuery having()

Returns SQL that set having by a given expression.

You can call having multiple times. Each call will add an expression with a logical and.

Example: $q->select( '*' )->from( 'table' )->groupBy( 'id' ) ->having( $q->expr->eq('id',1) );

Return Value

SelectQuery a pointer to $this

Exceptions

QueryException if called with no parameters.

at line 573
public string getQuery()

Returns the query string for this query object.

Return Value

string

Exceptions

QueryException if it was not possible to build a valid query.