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
protected $where
protected $joinCondition
protected $conditions
protected $parameters
protected $order
protected $limit
protected $offset
protected $group
protected $having
protected $reservedTableNames
protected $aliases
protected $currentAlias

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(string $columns, ...$params)

No description

array
getSelect()

No description

void
resetSelect()

No description

bool
addWhere(string|array $condition, ...$params)

No description

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

No description

bool
addCondition(string|array $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(string|array $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(string|array $columns, ...$params)

No description

string
getGroup()

No description

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

No description

string
getHaving()

No description

string
buildSelect(array $columns)

No description

array
parseJoinConditions(array $joins, array $joinConditions)

No description

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

No description

void
parseJoins(array $joins, string $query)

No description

string
parseJoinsCb(array $joins, array $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 55
__construct(string $tableName, Explorer $explorer)

No description

Parameters

string $tableName
Explorer $explorer

at line 67
string getTableName()

No description

Return Value

string

at line 73
string buildInsertQuery()

No description

Return Value

string

at line 79
string buildUpdateQuery()

No description

Return Value

string

at line 95
string buildDeleteQuery()

No description

Return Value

string

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

Returns select query hash for caching.

Parameters

array|null $columns

Return Value

string

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

Returns SQL query.

Parameters

array|null $columns

Return Value

string

at line 192
array getParameters()

No description

Return Value

array

at line 209
void importConditions(SqlBuilder $builder)

No description

Parameters

SqlBuilder $builder

Return Value

void

at line 221
bool importGroupConditions(SqlBuilder $builder)

No description

Parameters

SqlBuilder $builder

Return Value

bool

at line 238
void addSelect(string $columns, ...$params)

No description

Parameters

string $columns
...$params

Return Value

void

at line 245
array getSelect()

No description

Return Value

array

at line 251
void resetSelect()

No description

Return Value

void

at line 258
bool addWhere(string|array $condition, ...$params)

No description

Parameters

string|array $condition
...$params

Return Value

bool

at line 264
bool addJoinCondition(string $tableChain, string|array $condition, ...$params)

No description

Parameters

string $tableChain
string|array $condition
...$params

Return Value

bool

at line 275
protected bool addCondition(string|array $condition, array $params, array $conditions, array $conditionsParameters)

No description

Parameters

string|array $condition
array $params
array $conditions
array $conditionsParameters

Return Value

bool

at line 405
array getConditions()

No description

Return Value

array

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

Adds alias.

Parameters

string $chain
string $alias

Return Value

void

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

No description

Parameters

string $tableName
string $chain

Return Value

void

at line 443
void addOrder(string|array $columns, ...$params)

No description

Parameters

string|array $columns
...$params

Return Value

void

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

No description

Parameters

array $columns
array $parameters

Return Value

void

at line 457
array getOrder()

No description

Return Value

array

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

No description

Parameters

int|null $limit
int|null $offset

Return Value

void

at line 470
int|null getLimit()

No description

Return Value

int|null

at line 476
int|null getOffset()

No description

Return Value

int|null

at line 482
void setGroup(string|array $columns, ...$params)

No description

Parameters

string|array $columns
...$params

Return Value

void

at line 489
string getGroup()

No description

Return Value

string

at line 495
void setHaving(string $having, ...$params)

No description

Parameters

string $having
...$params

Return Value

void

at line 502
string getHaving()

No description

Return Value

string

at line 511
protected string buildSelect(array $columns)

No description

Parameters

array $columns

Return Value

string

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

No description

Parameters

array $joins
array $joinConditions

Return Value

array

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

No description

Parameters

string $table
array $leftJoinDependency
array $tableJoins
array $finalJoins

Return Value

void

at line 606
protected void parseJoins(array $joins, string $query)

No description

Parameters

array $joins
string $query

Return Value

void

at line 622
string parseJoinsCb(array $joins, array $match)

No description

Parameters

array $joins
array $match

Return Value

string

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

No description

Parameters

array $joins
array $leftJoinConditions

Return Value

string

at line 754
protected array buildJoinConditions()

No description

Return Value

array

at line 765
protected string buildConditions()

No description

Return Value

string

at line 773
protected string buildQueryEnd()

No description

Return Value

string

at line 792
protected string tryDelimite(string $s)

No description

Parameters

string $s

Return Value

string

at line 804
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