class DBQueryBuilder (View source)

Builds a SQL query string from a SQLExpression object

Traits

Provides extensions to this object to integrate it with standard config API methods.

Config options

trace_query_origin bool

If true, a comment is added to each query indicating where that query's execution originated.

Properties

Methods

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public
string
getSeparator()

Determines the line separator to use.

public
string
buildSQL(SQLExpression $query, array $parameters)

Builds a sql query with the specified connection

protected
string
buildTraceComment()

Builds an SQL comment indicating where the query was executed from.

protected
string
buildSelectQuery(SQLSelect $query, array $parameters)

Builds a query from a SQLSelect expression

protected
string
buildDeleteQuery(SQLDelete $query, array $parameters)

Builds a query from a SQLDelete expression

protected
string
buildInsertQuery(SQLInsert $query, array $parameters)

Builds a query from a SQLInsert expression

protected
string
buildUpdateQuery(SQLUpdate $query, array $parameters)

Builds a query from a SQLUpdate expression

protected
string
buildWithFragment(SQLSelect $query, array $parameters)

Returns the WITH clauses ready for inserting into a query.

protected
string
buildSelectFragment(SQLSelect $query, array $parameters)

Returns the SELECT clauses ready for inserting into a query.

public
string
buildDeleteFragment(SQLDelete $query, array $parameters)

Return the DELETE clause ready for inserting into a query.

public
string
buildUpdateFragment(SQLUpdate $query, array $parameters)

Return the UPDATE clause ready for inserting into a query.

public
string
buildFromFragment(SQLConditionalExpression $query, array $parameters)

Return the FROM clause ready for inserting into a query.

public
string
buildWhereFragment(SQLConditionalExpression $query, array $parameters)

Returns the WHERE clauses ready for inserting into a query.

protected
string
buildUnionFragment(SQLSelect $query, array $parameters)

Return the UNION clause(s) ready for inserting into a query.

public
string
buildOrderByFragment(SQLSelect $query, array $parameters)

Returns the ORDER BY clauses ready for inserting into a query.

public
string
buildGroupByFragment(SQLSelect $query, array $parameters)

Returns the GROUP BY clauses ready for inserting into a query.

public
string
buildHavingFragment(SQLSelect $query, array $parameters)

Returns the HAVING clauses ready for inserting into a query.

public
string
buildLimitFragment(SQLSelect $query, array $parameters)

Return the LIMIT clause ready for inserting into a query.

Details

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

string getSeparator()

Determines the line separator to use.

Return Value

string

Non-empty whitespace character

string buildSQL(SQLExpression $query, array $parameters)

Builds a sql query with the specified connection

Parameters

SQLExpression $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

The resulting SQL as a string

protected string buildTraceComment()

Builds an SQL comment indicating where the query was executed from.

Return Value

string

protected string buildSelectQuery(SQLSelect $query, array $parameters)

Builds a query from a SQLSelect expression

Parameters

SQLSelect $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed SQL string

protected string buildDeleteQuery(SQLDelete $query, array $parameters)

Builds a query from a SQLDelete expression

Parameters

SQLDelete $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed SQL string

protected string buildInsertQuery(SQLInsert $query, array $parameters)

Builds a query from a SQLInsert expression

Parameters

SQLInsert $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed SQL string

protected string buildUpdateQuery(SQLUpdate $query, array $parameters)

Builds a query from a SQLUpdate expression

Parameters

SQLUpdate $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed SQL string

protected string buildWithFragment(SQLSelect $query, array $parameters)

Returns the WITH clauses ready for inserting into a query.

Parameters

SQLSelect $query
array $parameters

Return Value

string

protected string buildSelectFragment(SQLSelect $query, array $parameters)

Returns the SELECT clauses ready for inserting into a query.

Parameters

SQLSelect $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed select part of statement

string buildDeleteFragment(SQLDelete $query, array $parameters)

Return the DELETE clause ready for inserting into a query.

Parameters

SQLDelete $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed delete part of statement

string buildUpdateFragment(SQLUpdate $query, array $parameters)

Return the UPDATE clause ready for inserting into a query.

Parameters

SQLUpdate $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed from part of statement

string buildFromFragment(SQLConditionalExpression $query, array $parameters)

Return the FROM clause ready for inserting into a query.

Parameters

SQLConditionalExpression $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed from part of statement

string buildWhereFragment(SQLConditionalExpression $query, array $parameters)

Returns the WHERE clauses ready for inserting into a query.

Parameters

SQLConditionalExpression $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed where condition

protected string buildUnionFragment(SQLSelect $query, array $parameters)

Return the UNION clause(s) ready for inserting into a query.

Parameters

SQLSelect $query
array $parameters

Return Value

string

string buildOrderByFragment(SQLSelect $query, array $parameters)

Returns the ORDER BY clauses ready for inserting into a query.

Parameters

SQLSelect $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed order by part of statement

string buildGroupByFragment(SQLSelect $query, array $parameters)

Returns the GROUP BY clauses ready for inserting into a query.

Parameters

SQLSelect $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

Completed group part of statement

string buildHavingFragment(SQLSelect $query, array $parameters)

Returns the HAVING clauses ready for inserting into a query.

Parameters

SQLSelect $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

string buildLimitFragment(SQLSelect $query, array $parameters)

Return the LIMIT clause ready for inserting into a query.

Parameters

SQLSelect $query

The expression object to build from

array $parameters

Out parameter for the resulting query parameters

Return Value

string

The finalised limit SQL fragment