class CRM_Utils_SQL_BaseParamQuery implements ArrayAccess

Class CRM_Utils_SQL_BaseParamQuery

Base class for query-building which handles parameter interpolation.

Constants

INTERPOLATE_INPUT

Interpolate values as soon as they are passed in (where(), join(), etc).

Default.

Pro: Every clause has its own unique namespace for parameters. Con: Probably slower. Advice: Use this when aggregating SQL fragments from agents who maintained by different parties.

INTERPOLATE_OUTPUT

Interpolate values when rendering SQL output (toSQL()).

Pro: Probably faster. Con: Must maintain an aggregated list of all parameters. Advice: Use this when you have control over the entire query.

INTERPOLATE_AUTO

Determine mode automatically. When the first attempt is made to use input-interpolation (eg `where(.

.., array(...))) or output-interpolation (egparam(...)`), the mode will be set. Subsequent calls will be validated using the same mode.

Properties

protected mixed $mode
protected array $params
bool $strict Public to work-around PHP 5.3 limit.

Methods

strict(bool $strict = TRUE)

Enable (or disable) strict mode.

string
interpolate(string $expr, null|array $args, string $activeMode = self::INTERPOLATE_INPUT)

Given a string like "field_name = @value", replace "@value" with an escaped SQL string

string
escapeString(string|NULL $value)

No description

$this
param(array|string $keys, null|mixed $value = NULL)

Set one (or multiple) parameters to interpolate into the query.

bool
offsetExists(string $offset)

Has an offset been set.

mixed
offsetGet(string $offset)

Get the value of a SQL parameter.

offsetSet(string $offset, mixed $value)

Set the value of a SQL parameter.

offsetUnset(string $offset)

Unset the value of a SQL parameter.

Details

at line 63
CRM_Utils_SQL_BaseParamQuery strict(bool $strict = TRUE)

Enable (or disable) strict mode.

In strict mode, unknown variables will generate exceptions.

Parameters

bool $strict

Return Value

CRM_Utils_SQL_BaseParamQuery

at line 84
string interpolate(string $expr, null|array $args, string $activeMode = self::INTERPOLATE_INPUT)

Given a string like "field_name = @value", replace "@value" with an escaped SQL string

Parameters

string $expr SQL expression
null|array $args a list of values to insert into the SQL expression; keys are prefix-coded: prefix '@' => escape SQL prefix '#' => literal number, skip escaping but do validation prefix '!' => literal, skip escaping and validation if a value is an array, then it will be imploded

PHP NULL's will be treated as SQL NULL's. The PHP string "null" will be treated as a string.

string $activeMode

Return Value

string

at line 146
string escapeString(string|NULL $value)

Parameters

string|NULL $value

Return Value

string SQL expression, e.g. "it\'s great" (with-quotes) or NULL (without-quotes)

at line 161
$this param(array|string $keys, null|mixed $value = NULL)

Set one (or multiple) parameters to interpolate into the query.

Parameters

array|string $keys Key name, or an array of key-value pairs.
null|mixed $value The new value of the parameter. Values may be strings, ints, or arrays thereof -- provided that the SQL query uses appropriate prefix (e.g. "@", "!", "#").

Return Value

$this

at line 187
bool offsetExists(string $offset)

Has an offset been set.

Parameters

string $offset

Return Value

bool

at line 205
mixed offsetGet(string $offset)

Get the value of a SQL parameter.

Parameters

string $offset

Return Value

mixed

See also

param()
ArrayAccess::offsetGet

at line 226
offsetSet(string $offset, mixed $value)

Set the value of a SQL parameter.

Parameters

string $offset
mixed $value The new value of the parameter. Values may be strings, ints, or arrays thereof -- provided that the SQL query uses appropriate prefix (e.g. "@", "!", "#").

See also

param()
ArrayAccess::offsetSet

at line 237
offsetUnset(string $offset)

Unset the value of a SQL parameter.

Parameters

string $offset

See also

param()
ArrayAccess::offsetUnset