Documentation

CRM_Utils_SQL_BaseParamQuery
in package
implements ArrayAccess uses CRM_Utils_SQL_EscapeStringTrait

Class CRM_Utils_SQL_BaseParamQuery

Base class for query-building which handles parameter interpolation.

Table of Contents

Interfaces

ArrayAccess

Constants

INTERPOLATE_AUTO  = 'auto'
Determine mode automatically. When the first attempt is made to use input-interpolation (eg `where(..., array(...))`) or output-interpolation (eg `param(...)`), the mode will be set. Subsequent calls will be validated using the same mode.
INTERPOLATE_INPUT  = 'in'
Interpolate values as soon as they are passed in (where(), join(), etc).
INTERPOLATE_OUTPUT  = 'out'
Interpolate values when rendering SQL output (toSQL()).

Properties

$strict  : bool
Public to work-around PHP 5.3 limit.
$allowLiterals  : mixed
$mode  : mixed
$params  : array<string|int, mixed>

Methods

allowLiterals()  : mixed
escapeString()  : string
interpolate()  : string
Given a string like "field_name = @value", replace "@value" with an escaped SQL string
offsetExists()  : bool
Has an offset been set.
offsetGet()  : mixed
Get the value of a SQL parameter.
offsetSet()  : void
Set the value of a SQL parameter.
offsetUnset()  : void
Unset the value of a SQL parameter.
param()  : $this
Set one (or multiple) parameters to interpolate into the query.
strict()  : self
Enable (or disable) strict mode.

Constants

INTERPOLATE_AUTO

Determine mode automatically. When the first attempt is made to use input-interpolation (eg `where(..., array(...))`) or output-interpolation (eg `param(...)`), the mode will be set. Subsequent calls will be validated using the same mode.

public mixed INTERPOLATE_AUTO = 'auto'

INTERPOLATE_INPUT

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

public mixed INTERPOLATE_INPUT = 'in'

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()).

public mixed INTERPOLATE_OUTPUT = 'out'

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

Properties

$strict

Public to work-around PHP 5.3 limit.

public bool $strict = \NULL

Methods

allowLiterals()

public allowLiterals([bool $allowLiterals = TRUE ]) : mixed
Parameters
$allowLiterals : bool = TRUE

escapeString()

public escapeString(string|null $value) : string
Parameters
$value : string|null
Return values
string

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

interpolate()

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

public interpolate(string $expr, null|array<string|int, mixed> $args[, string $activeMode = self::INTERPOLATE_INPUT ]) : string
Parameters
$expr : string

SQL expression

$args : null|array<string|int, mixed>

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.

$activeMode : string = self::INTERPOLATE_INPUT
Return values
string

offsetExists()

Has an offset been set.

public offsetExists(string $offset) : bool
Parameters
$offset : string
Return values
bool

offsetGet()

Get the value of a SQL parameter.

public offsetGet(string $offset) : mixed
  $select['cid'] = 123;
  $select->where('contact.id = #cid');
  echo $select['cid'];
Parameters
$offset : string
Tags
see
param()
see
ArrayAccess::offsetGet
Attributes
#[ReturnTypeWillChange]

offsetSet()

Set the value of a SQL parameter.

public offsetSet(string $offset, mixed $value) : void
  $select['cid'] = 123;
  $select->where('contact.id = #cid');
  echo $select['cid'];
Parameters
$offset : string
$value : mixed

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

Tags
see
param()
see
ArrayAccess::offsetSet

offsetUnset()

Unset the value of a SQL parameter.

public offsetUnset(string $offset) : void
Parameters
$offset : string
Tags
see
param()
see
ArrayAccess::offsetUnset

param()

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

public param(array<string|int, mixed>|string $keys[, null|mixed $value = NULL ]) : $this
Parameters
$keys : array<string|int, mixed>|string

Key name, or an array of key-value pairs.

$value : null|mixed = NULL

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 values
$this

strict()

Enable (or disable) strict mode.

public strict([bool $strict = TRUE ]) : self

In strict mode, unknown variables will generate exceptions.

Parameters
$strict : bool = TRUE
Return values
self

        
On this page

Search results