class SqlBuilder

Builds SQL query.

SqlBuilder is based on great library NotORM http://www.notorm.com written by Jakub Vrana.

Properties

protected $tableName
protected $conventions
protected $delimitedTable
protected $select

column to select

protected $where
protected $joinCondition
protected $conditions

where conditions for caching

protected $parameters

parameters passed to where conditions

protected $order

columns to order by

protected $limit

number of rows to fetch

protected $offset

first row to fetch

protected $group

columns to grouping

protected $having

grouping condition

protected $reservedTableNames

reserved table names associated with chain

protected $aliases

table aliases

protected $currentAlias

currently parsing alias for joins

Methods

__construct(string $tableName, Explorer $explorer)

No description

string
getTableName()

No description

string
buildInsertQuery()

No description

string
buildUpdateQuery()

No description

string
buildDeleteQuery()

No description

string
getSelectQueryHash(array|null $columns = null)

Returns select query hash for caching.

string
buildSelectQuery(array|null $columns = null)

Returns SQL query.

array
getParameters()

No description

void
importConditions(SqlBuilder $builder)

No description

bool
importGroupConditions(SqlBuilder $builder)

No description

void
addSelect($columns, ...$params)

No description

array
getSelect()

No description

void
resetSelect()

No description

bool
addWhere($condition, ...$params)

No description

bool
addJoinCondition(string $tableChain, $condition, ...$params)

No description

bool
addCondition($condition, array $params, array $conditions, array $conditionsParameters)

No description

array
getConditions()

No description

void
addAlias(string $chain, string $alias)

Adds alias.

void
checkUniqueTableName(string $tableName, string $chain)

No description

void
addOrder($columns, ...$params)

No description

void
setOrder(array $columns, array $parameters)

No description

array
getOrder()

No description

void
setLimit(int|null $limit, int|null $offset)

No description

int|null
getLimit()

No description

int|null
getOffset()

No description

void
setGroup($columns, ...$params)

No description

string
getGroup()

No description

void
setHaving($having, ...$params)

No description

string
getHaving()

No description

string
buildSelect(array $columns)

No description

array
parseJoinConditions($joins, $joinConditions)

No description

void
getSortedJoins(string $table, $leftJoinDependency, $tableJoins, $finalJoins)

No description

void
parseJoins($joins, $query)

No description

string
parseJoinsCb($joins, $match)

No description

string
buildQueryJoins(array $joins, array $leftJoinConditions = [])

No description

array
buildJoinConditions()

No description

string
buildConditions()

No description

string
buildQueryEnd()

No description

string
tryDelimite(string $s)

No description

bool
addConditionComposition(array $columns, array $parameters, array $conditions, array $conditionsParameters)

No description

Details

at line 88
__construct(string $tableName, Explorer $explorer)

No description

Parameters

string $tableName
Explorer $explorer

at line 100
string getTableName()

No description

Return Value

string

at line 106
string buildInsertQuery()

No description

Return Value

string

at line 112
string buildUpdateQuery()

No description

Return Value

string

at line 128
string buildDeleteQuery()

No description

Return Value

string

at line 142
string getSelectQueryHash(array|null $columns = null)

Returns select query hash for caching.

Parameters

array|null $columns

Return Value

string

at line 176
string buildSelectQuery(array|null $columns = null)

Returns SQL query.

Parameters

array|null $columns

Return Value

string

at line 225
array getParameters()

No description

Return Value

array

at line 242
void importConditions(SqlBuilder $builder)

No description

Parameters

SqlBuilder $builder

Return Value

void

at line 254
bool importGroupConditions(SqlBuilder $builder)

No description

Parameters

SqlBuilder $builder

Return Value

bool

at line 271
void addSelect($columns, ...$params)

No description

Parameters

$columns
...$params

Return Value

void

at line 282
array getSelect()

No description

Return Value

array

at line 288
void resetSelect()

No description

Return Value

void

at line 295
bool addWhere($condition, ...$params)

No description

Parameters

$condition
...$params

Return Value

bool

at line 301
bool addJoinCondition(string $tableChain, $condition, ...$params)

No description

Parameters

string $tableChain
$condition
...$params

Return Value

bool

at line 312
protected bool addCondition($condition, array $params, array $conditions, array $conditionsParameters)

No description

Parameters

$condition
array $params
array $conditions
array $conditionsParameters

Return Value

bool

at line 434
array getConditions()

No description

Return Value

array

at line 443
void addAlias(string $chain, string $alias)

Adds alias.

Parameters

string $chain
string $alias

Return Value

void

at line 454
protected void checkUniqueTableName(string $tableName, string $chain)

No description

Parameters

string $tableName
string $chain

Return Value

void

at line 472
void addOrder($columns, ...$params)

No description

Parameters

$columns
...$params

Return Value

void

at line 479
void setOrder(array $columns, array $parameters)

No description

Parameters

array $columns
array $parameters

Return Value

void

at line 486
array getOrder()

No description

Return Value

array

at line 492
void setLimit(int|null $limit, int|null $offset)

No description

Parameters

int|null $limit
int|null $offset

Return Value

void

at line 499
int|null getLimit()

No description

Return Value

int|null

at line 505
int|null getOffset()

No description

Return Value

int|null

at line 511
void setGroup($columns, ...$params)

No description

Parameters

$columns
...$params

Return Value

void

at line 518
string getGroup()

No description

Return Value

string

at line 524
void setHaving($having, ...$params)

No description

Parameters

$having
...$params

Return Value

void

at line 531
string getHaving()

No description

Return Value

string

at line 540
protected string buildSelect(array $columns)

No description

Parameters

array $columns

Return Value

string

at line 546
protected array parseJoinConditions($joins, $joinConditions)

No description

Parameters

$joins
$joinConditions

Return Value

array

at line 582
protected void getSortedJoins(string $table, $leftJoinDependency, $tableJoins, $finalJoins)

No description

Parameters

string $table
$leftJoinDependency
$tableJoins
$finalJoins

Return Value

void

at line 627
protected void parseJoins($joins, $query)

No description

Parameters

$joins
$query

Return Value

void

at line 643
string parseJoinsCb($joins, $match)

No description

Parameters

$joins
$match

Return Value

string

at line 761
protected string buildQueryJoins(array $joins, array $leftJoinConditions = [])

No description

Parameters

array $joins
array $leftJoinConditions

Return Value

string

at line 775
protected array buildJoinConditions()

No description

Return Value

array

at line 786
protected string buildConditions()

No description

Return Value

string

at line 794
protected string buildQueryEnd()

No description

Return Value

string

at line 813
protected string tryDelimite(string $s)

No description

Parameters

string $s

Return Value

string

at line 821
protected bool addConditionComposition(array $columns, array $parameters, array $conditions, array $conditionsParameters)

No description

Parameters

array $columns
array $parameters
array $conditions
array $conditionsParameters

Return Value

bool

Traits

SmartObject