CRM_Utils_SQL_Select
class CRM_Utils_SQL_Select extends CRM_Utils_SQL_BaseParamQuery
Dear God Why Do I Have To Write This (Dumb SQL Builder)
Usage:
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(...)) |
Properties
protected mixed | $mode | from CRM_Utils_SQL_BaseParamQuery | |
protected array | $params | from CRM_Utils_SQL_BaseParamQuery | |
bool | $strict | Public to work-around PHP 5.3 limit. | from CRM_Utils_SQL_BaseParamQuery |
Methods
Enable (or disable) strict mode.
Given a string like "field_name = @value", replace "@value" with an escaped SQL string
Set one (or multiple) parameters to interpolate into the query.
Set the value of a SQL parameter.
Create a new SELECT query.
Create a partial SELECT query.
Create a new SELECT query.
Make a new copy of this query.
Add a new JOIN clause.
Specify the column(s)/value(s) to return by adding to the SELECT clause
Return only distinct values
Limit results by adding extra condition(s) to the WHERE clause
Group results by adding extra items to the GROUP BY clause.
Limit results by adding extra condition(s) to the HAVING clause
Sort results by adding extra items to the ORDER BY clause.
Set a limit on the number of records to return.
Insert the results of the SELECT query into another table.
Wrapper function of insertInto fn but sets insertVerb = "INSERT IGNORE INTO "
Wrapper function of insertInto fn but sets insertVerb = "REPLACE INTO "
No description
No description
No description
Execute the query.
Details
in CRM_Utils_SQL_BaseParamQuery at line 63
CRM_Utils_SQL_BaseParamQuery
strict(bool $strict = TRUE)
Enable (or disable) strict mode.
In strict mode, unknown variables will generate exceptions.
in 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
in CRM_Utils_SQL_BaseParamQuery at line 146
string
escapeString(string|NULL $value)
at line 323
$this
param(array|string $keys, null|mixed $value = NULL)
Set one (or multiple) parameters to interpolate into the query.
in CRM_Utils_SQL_BaseParamQuery at line 187
bool
offsetExists(string $offset)
Has an offset been set.
in CRM_Utils_SQL_BaseParamQuery at line 205
mixed
offsetGet(string $offset)
Get the value of a SQL parameter.
in CRM_Utils_SQL_BaseParamQuery at line 226
offsetSet(string $offset, mixed $value)
Set the value of a SQL parameter.
in CRM_Utils_SQL_BaseParamQuery at line 237
offsetUnset(string $offset)
Unset the value of a SQL parameter.
at line 107
static CRM_Utils_SQL_Select
from(string $from, array $options = [])
Create a new SELECT query.
at line 117
static CRM_Utils_SQL_Select
fragment(array $options = [])
Create a partial SELECT query.
at line 128
__construct(string $from, array $options = [])
Create a new SELECT query.
at line 138
CRM_Utils_SQL_Select
copy()
Make a new copy of this query.
at line 150
CRM_Utils_SQL_Select
merge(array|CRM_Utils_SQL_Select $other, array|NULL $parts = NULL)
Merge something or other.
at line 205
CRM_Utils_SQL_Select
join(string|NULL $name, string|array $exprs, array|null $args = NULL)
Add a new JOIN clause.
Note: To add multiple JOINs at once, use $name===NULL and pass an array of $exprs.
at line 225
CRM_Utils_SQL_Select
select(string|array $exprs, null|array $args = NULL)
Specify the column(s)/value(s) to return by adding to the SELECT clause
at line 239
CRM_Utils_SQL_Select
distinct(bool $isDistinct = TRUE)
Return only distinct values
at line 253
CRM_Utils_SQL_Select
where(string|array $exprs, null|array $args = NULL)
Limit results by adding extra condition(s) to the WHERE clause
at line 269
CRM_Utils_SQL_Select
groupBy(string|array $exprs, null|array $args = NULL)
Group results by adding extra items to the GROUP BY clause.
at line 285
CRM_Utils_SQL_Select
having(string|array $exprs, null|array $args = NULL)
Limit results by adding extra condition(s) to the HAVING clause
at line 302
CRM_Utils_SQL_Select
orderBy(string|array $exprs, null|array $args = NULL, int $weight = 0)
Sort results by adding extra items to the ORDER BY clause.
at line 336
CRM_Utils_SQL_Select
limit(int $limit, int $offset = 0)
Set a limit on the number of records to return.
at line 359
CRM_Utils_SQL_Select
insertInto(string $table, array $fields = [])
Insert the results of the SELECT query into another table.
at line 374
CRM_Utils_SQL_Select
insertIgnoreInto(string $table, array $fields = [])
Wrapper function of insertInto fn but sets insertVerb = "INSERT IGNORE INTO "
at line 387
replaceInto(string $table, array $fields = [])
Wrapper function of insertInto fn but sets insertVerb = "REPLACE INTO "
at line 397
CRM_Utils_SQL_Select
insertIntoField(array $fields)
at line 411
bool
isEmpty(array|NULL $parts = NULL)
at line 441
string
toSQL()
at line 504
CRM_Core_DAO
execute(string|NULL $daoName = NULL, bool $i18nRewrite = TRUE)
Execute the query.
To examine the results, use a function like fetch()
, fetchAll()
,
fetchValue()
, or fetchMap()
.