Documentation

SqlExpression
in package

AbstractYes

Base class for SqlColumn, SqlString, SqlBool, and SqlFunction classes.

These are used to validate and format sql expressions in Api4 select queries.

Table of Contents

Properties

$expr  : string
The raw expression, minus the alias.
$supportsExpansion  : bool
Whether or not pseudoconstant suffixes should be evaluated during output.
$alias  : string|null
The SELECT alias (if null it will be calculated by getAlias)
$dataType  : string
Data type output by this expression
$fields  : array<string|int, string>
Field names used in this expression

Methods

__construct()  : mixed
SqlFunction constructor.
convert()  : SqlExpression
Converts a string to a SqlExpression object.
getAlias()  : string
Returns the alias to use for SELECT AS.
getDataType()  : string|null
getExpr()  : string
getFields()  : array<string|int, mixed>
Returns the field names of all sql columns that are arguments to this expression.
getSerialize()  : int|null
Get value serialization method if any.
getTitle()  : string
getType()  : string
Returns the name of this sql expression class.
isType()  : bool
Checks the name of this sql expression class.
render()  : string
Renders expression to a sql string, replacing field names with column names.
captureExpression()  : string
Scans the beginning of a string for an expression; stops when it hits delimiter
captureExpressions()  : array<string|int, SqlExpression>
Shifts 0 or more expressions off the argument string and returns them
captureKeyword()  : mixed|null
Shift a keyword off the beginning of the argument string and return it.
initialize()  : mixed
munge()  : mixed

Properties

$expr

The raw expression, minus the alias.

public string $expr = ''

$supportsExpansion

Whether or not pseudoconstant suffixes should be evaluated during output.

public bool $supportsExpansion = FALSE
Tags
see
FormattingUtil::formatOutputValues

$alias

The SELECT alias (if null it will be calculated by getAlias)

protected string|null $alias

$dataType

Data type output by this expression

protected static string $dataType

$fields

Field names used in this expression

protected array<string|int, string> $fields = []

Methods

__construct()

SqlFunction constructor.

public __construct(string $expr[, string|null $alias = NULL ]) : mixed
Parameters
$expr : string
$alias : string|null = NULL

convert()

Converts a string to a SqlExpression object.

public static convert(string $expression[, bool $parseAlias = FALSE ][, array<string|int, mixed> $mustBe = [] ]) : SqlExpression

E.g. the expression "SUM(foo)" would return a SqlFunctionSUM object.

Parameters
$expression : string
$parseAlias : bool = FALSE
$mustBe : array<string|int, mixed> = []
Tags
throws
CRM_Core_Exception
Return values
SqlExpression

getAlias()

Returns the alias to use for SELECT AS.

public getAlias() : string
Return values
string

getDataType()

public static getDataType() : string|null
Return values
string|null

getFields()

Returns the field names of all sql columns that are arguments to this expression.

public getFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getSerialize()

Get value serialization method if any.

public getSerialize() : int|null
Return values
int|null

getTitle()

public abstract static getTitle() : string
Return values
string

getType()

Returns the name of this sql expression class.

public getType() : string
Return values
string

isType()

Checks the name of this sql expression class.

public isType(mixed $type) : bool
Parameters
$type : mixed
Return values
bool

render()

Renders expression to a sql string, replacing field names with column names.

public render(Api4Query $query[, bool $includeAlias = FALSE ]) : string
Parameters
$query : Api4Query
$includeAlias : bool = FALSE
Return values
string

captureExpression()

Scans the beginning of a string for an expression; stops when it hits delimiter

protected captureExpression(mixed $arg) : string
Parameters
$arg : mixed
Return values
string

captureExpressions()

Shifts 0 or more expressions off the argument string and returns them

protected captureExpressions(string &$arg, array<string|int, mixed> $mustBe, int $max) : array<string|int, SqlExpression>
Parameters
$arg : string
$mustBe : array<string|int, mixed>
$max : int
Tags
throws
CRM_Core_Exception
Return values
array<string|int, SqlExpression>

captureKeyword()

Shift a keyword off the beginning of the argument string and return it.

protected captureKeyword(array<string|int, mixed> $keywords, string &$arg) : mixed|null
Parameters
$keywords : array<string|int, mixed>

Whitelist of keywords

$arg : string
Return values
mixed|null

munge()

private static munge(mixed $name[, mixed $char = '_' ][, mixed $len = 63 ]) : mixed
Parameters
$name : mixed
$char : mixed = '_'
$len : mixed = 63

        
On this page

Search results