class ExpressionBuilder (View source)

ExpressionBuilder class is responsible to dynamically create SQL query parts.

Constants

EQ

NEQ

LT

LTE

GT

GTE

Methods

__construct(Connection $connection)

Initializes a new ExpressionBuilder.

andX(mixed $x = null)

Creates a conjunction of the given boolean expressions.

orX(mixed $x = null)

Creates a disjunction of the given boolean expressions.

string
comparison(mixed $x, string $operator, mixed $y)

Creates a comparison expression.

string
eq(mixed $x, mixed $y)

Creates an equality comparison expression with the given arguments.

string
neq(mixed $x, mixed $y)

Creates a non equality comparison expression with the given arguments.

string
lt(mixed $x, mixed $y)

Creates a lower-than comparison expression with the given arguments.

string
lte(mixed $x, mixed $y)

Creates a lower-than-equal comparison expression with the given arguments.

string
gt(mixed $x, mixed $y)

Creates a greater-than comparison expression with the given arguments.

string
gte(mixed $x, mixed $y)

Creates a greater-than-equal comparison expression with the given arguments.

string
isNull(string $x)

Creates an IS NULL expression with the given arguments.

string
isNotNull(string $x)

Creates an IS NOT NULL expression with the given arguments.

string
like(string $x, mixed $y)

Creates a LIKE() comparison expression with the given arguments.

string
literal(mixed $input, string $type = null)

Quotes a given input parameter.

Details

__construct(Connection $connection)

Initializes a new ExpressionBuilder.

Parameters

Connection $connection DBAL Connection

CompositeExpression andX(mixed $x = null)

Creates a conjunction of the given boolean expressions.

Example:

[php]
// (u.type = ?) AND (u.role = ?)
$expr->andX('u.type = ?', 'u.role = ?'));

Parameters

mixed $x Optional clause. Defaults = null, but requires at least one defined when converting to string.

Return Value

CompositeExpression

CompositeExpression orX(mixed $x = null)

Creates a disjunction of the given boolean expressions.

Example:

[php]
// (u.type = ?) OR (u.role = ?)
$qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?'));

Parameters

mixed $x Optional clause. Defaults = null, but requires at least one defined when converting to string.

Return Value

CompositeExpression

string comparison(mixed $x, string $operator, mixed $y)

Creates a comparison expression.

Parameters

mixed $x Left expression
string $operator One of the ExpressionBuilder::* constants.
mixed $y Right expression

Return Value

string

string eq(mixed $x, mixed $y)

Creates an equality comparison expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a = . Example:

[php]
// u.id = ?
$expr->eq('u.id', '?');

Parameters

mixed $x Left expression
mixed $y Right expression

Return Value

string

string neq(mixed $x, mixed $y)

Creates a non equality comparison expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a <> . Example:

[php]
// u.id <> 1
$q->where($q->expr()->neq('u.id', '1'));

Parameters

mixed $x Left expression
mixed $y Right expression

Return Value

string

string lt(mixed $x, mixed $y)

Creates a lower-than comparison expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a < . Example:

[php]
// u.id < ?
$q->where($q->expr()->lt('u.id', '?'));

Parameters

mixed $x Left expression
mixed $y Right expression

Return Value

string

string lte(mixed $x, mixed $y)

Creates a lower-than-equal comparison expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a <= . Example:

[php]
// u.id <= ?
$q->where($q->expr()->lte('u.id', '?'));

Parameters

mixed $x Left expression
mixed $y Right expression

Return Value

string

string gt(mixed $x, mixed $y)

Creates a greater-than comparison expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a > . Example:

[php]
// u.id > ?
$q->where($q->expr()->gt('u.id', '?'));

Parameters

mixed $x Left expression
mixed $y Right expression

Return Value

string

string gte(mixed $x, mixed $y)

Creates a greater-than-equal comparison expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a >= . Example:

[php]
// u.id >= ?
$q->where($q->expr()->gte('u.id', '?'));

Parameters

mixed $x Left expression
mixed $y Right expression

Return Value

string

string isNull(string $x)

Creates an IS NULL expression with the given arguments.

Parameters

string $x Field in string format to be restricted by IS NULL

Return Value

string

string isNotNull(string $x)

Creates an IS NOT NULL expression with the given arguments.

Parameters

string $x Field in string format to be restricted by IS NOT NULL

Return Value

string

string like(string $x, mixed $y)

Creates a LIKE() comparison expression with the given arguments.

Parameters

string $x Field in string format to be inspected by LIKE() comparison.
mixed $y Argument to be used in LIKE() comparison.

Return Value

string

string literal(mixed $input, string $type = null)

Quotes a given input parameter.

Parameters

mixed $input Parameter to be quoted.
string $type Type of the parameter.

Return Value

string