Doctrine\DBAL\Query\QueryBuilder
QueryBuilder class is responsible to dynamically create SQL queries.
Important: Verify that every feature you use will work with your database vendor.
SQL Query Builder does not attempt to validate the generated SQL at all.
The query builder does no validation whatsoever if certain features even work with the
underlying database vendor. Limit queries and joins are NOT applied to UPDATE and DELETE statements
even if some vendors such as MySQL support it.
- Author: Guilherme Blanco <guilhermeblanco@hotmail.com>
- License: http://www.opensource.org/licenses/lgpl-license.php LGPL
Synopsis
class QueryBuilder
{
- // constants
- const SELECT = 0;
- const DELETE = 1;
- const UPDATE = 2;
- const STATE_DIRTY = 0;
- const STATE_CLEAN = 1;
- // members
- private Connection $connection;
- private array $sqlParts;
- private string $sql;
- private array $params;
- private array $paramTypes;
- private integer $type;
- private integer $state;
- private integer $firstResult;
- private integer $maxResults;
- private integer $boundCounter;
- // methods
- public void __construct()
- public ExpressionBuilder expr()
- public integer getType()
- public Connection getConnection()
- public integer getState()
- public mixed execute()
- public string getSQL()
- public QueryBuilder setParameter()
- public QueryBuilder setParameters()
- public array getParameters()
- public mixed getParameter()
- public QueryBuilder setFirstResult()
- public integer getFirstResult()
- public QueryBuilder setMaxResults()
- public integer getMaxResults()
- public QueryBuilder add()
- public QueryBuilder select()
- public QueryBuilder addSelect()
- public QueryBuilder delete()
- public QueryBuilder update()
- public QueryBuilder from()
- public QueryBuilder join()
- public QueryBuilder innerJoin()
- public QueryBuilder leftJoin()
- public QueryBuilder rightJoin()
- public QueryBuilder set()
- public QueryBuilder where()
- public QueryBuilder andWhere()
- public QueryBuilder orWhere()
- public QueryBuilder groupBy()
- public QueryBuilder addGroupBy()
- public QueryBuilder having()
- public QueryBuilder andHaving()
- public QueryBuilder orHaving()
- public QueryBuilder orderBy()
- public QueryBuilder addOrderBy()
- public mixed getQueryPart()
- public array getQueryParts()
- public QueryBuilder resetQueryParts()
- public QueryBuilder resetQueryPart()
- private void getSQLForSelect()
- private string getSQLForUpdate()
- private string getSQLForDelete()
- public string __toString()
- public string createNamedParameter()
- public string createPositionalParameter()
Constants
Name | Value |
---|---|
SELECT | 0 |
DELETE | 1 |
UPDATE | 2 |
STATE_DIRTY | 0 |
STATE_CLEAN | 1 |
Members
private
- $boundCounter
—
int
The counter of bound parameters used with {@see bindValue) - $connection — Doctrine\DBAL\Query\Doctrine\DBAL\Connection
- $firstResult — integer
- $maxResults — integer
- $paramTypes — array
- $params — array
- $sql — string
- $sqlParts — array
- $state — integer
- $type — integer
Methods
private
- getSQLForDelete() — Converts this instance into a DELETE string in SQL.
- getSQLForSelect()
- getSQLForUpdate() — Converts this instance into an UPDATE string in SQL.
public
- __construct() — Initializes a new <tt>QueryBuilder</tt>.
- __toString() — Gets a string representation of this QueryBuilder which corresponds to the final SQL query being constructed.
- add() — Either appends to or replaces a single, generic query part.
- addGroupBy() — Adds a grouping expression to the query.
- addOrderBy() — Adds an ordering to the query results.
- addSelect() — Adds an item that is to be returned in the query result.
- andHaving() — Adds a restriction over the groups of the query, forming a logical conjunction with any existing having restrictions.
- andWhere() — Adds one or more restrictions to the query results, forming a logical conjunction with any previously specified restrictions.
- createNamedParameter() — Create a new named parameter and bind the value $value to it.
- createPositionalParameter() — Create a new positional parameter and bind the given value to it.
- delete() — Turns the query being built into a bulk delete query that ranges over a certain table.
- execute() — Execute this query using the bound parameters and their types.
- expr() — Gets an ExpressionBuilder used for object-oriented construction of query expressions.
- from() — Create and add a query root corresponding to the table identified by the given alias, forming a cartesian product with any existing query roots.
- getConnection() — Get the associated DBAL Connection for this query builder.
- getFirstResult() — Gets the position of the first result the query object was set to retrieve (the "offset").
- getMaxResults() — Gets the maximum number of results the query object was set to retrieve (the "limit").
- getParameter() — Gets a (previously set) query parameter of the query being constructed.
- getParameters() — Gets all defined query parameters for the query being constructed.
- getQueryPart() — Get a query part by its name.
- getQueryParts() — Get all query parts.
- getSQL() — Get the complete SQL string formed by the current specifications of this QueryBuilder.
- getState() — Get the state of this query builder instance.
- getType() — Get the type of the currently built query.
- groupBy() — Specifies a grouping over the results of the query.
- having() — Specifies a restriction over the groups of the query.
- innerJoin() — Creates and adds a join to the query.
- join() — Creates and adds a join to the query.
- leftJoin() — Creates and adds a left join to the query.
- orHaving() — Adds a restriction over the groups of the query, forming a logical disjunction with any existing having restrictions.
- orWhere() — Adds one or more restrictions to the query results, forming a logical disjunction with any previously specified restrictions.
- orderBy() — Specifies an ordering for the query results.
- resetQueryPart() — Reset single SQL part
- resetQueryParts() — Reset SQL parts
- rightJoin() — Creates and adds a right join to the query.
- select() — Specifies an item that is to be returned in the query result.
- set() — Sets a new value for a column in a bulk update query.
- setFirstResult() — Sets the position of the first result to retrieve (the "offset").
- setMaxResults() — Sets the maximum number of results to retrieve (the "limit").
- setParameter() — Sets a query parameter for the query being constructed.
- setParameters() — Sets a collection of query parameters for the query being constructed.
- update() — Turns the query being built into a bulk update query that ranges over a certain table
- where() — Specifies one or more restrictions to the query result.