Base class for all queries

package salt\sql\queries
inherited_from \salt\SqlBindField

 Methods

Construct a new query

__construct(\salt\Base $obj) 

Parameters

$obj

\salt\Base

the object used for retrieve metadata.

If parameter is empty, the query will not be executed

disableIfEmpty(mixed $list) 

This can be used if the query contains an IN where condition with an empty array : Executing the query result in an exception, but we can use this function for return an empty result without exception :

$q->whereAnd('ids', 'IN', $values); // will produce a bad where clause : "ids IN ()" if $values is empty
$q->disabledIfEmpty($values);
$db->execQuery($q); // valid, will not execute query, so not throw exception

Parameters

$list

mixed

Escape a name for SQL use with backquote

escapeName(string $name) : string
InheritedStatic

Parameters

$name

string

a SQL name : database, table, field, alias, etc...

Returns

stringSQL escaped text with backquote.

Return all binds

getBinds(string $source = \salt\ClauseType::ALL) : array<mixed,mixed[]>
Inherited

Parameters

$source

string

(Optional) ClauseType or specific text for restrict returned binds to specified source

Returns

array<mixed,mixed[]>list of binds : array of array('value' => ..., 'type' => ...)

Retrieve binds for pagination (LIMIT clause)

getPaginationBinds(\salt\Pagination $pagination) : array<mixed,mixed[]>
InheritedStatic

Parameters

$pagination

\salt\Pagination

the Pagination object

Returns

array<mixed,mixed[]>binds for the Pagination : array of bindName => array of ('value' => ..., 'type' => ...)

Check if we have to execute the query

isEnabled() : boolean

Returns

booleanTRUE if the query can be executed, FALSE otherwise

Check binds are private

isPrivateBinds() : boolean
Inherited

Returns

booleanTRUE if privateBinds has been called

Set all binds values as private. They will be hidden in debug queries

privateBinds(boolean $privateBinds = TRUE) : \salt\SqlBindField
Inherited

Parameters

$privateBinds

boolean

(Optional, TRUE) hide binds values in debug queries

Returns

\salt\SqlBindFieldthe current object

Retrieve the COUNT query

toCountQuery() : \salt\CountQuery

Have to be overrided by child classes if needed

Exceptions

\salt\SaltException if called on BaseQuery instance

Returns

\salt\CountQuerythe SQL query for count query

Retrieve the SQL text

toSQL() : string
Inherited

Returns

stringthe memoized SQL text

Add a bind

addBind(mixed $value, integer $type, string $source = \salt\ClauseType::ALL) : string
Inherited

Parameters

$value

mixed

value of bind

$type

integer

(FieldType) type of the field

$source

string

(Optional) ClauseType or other text : clause where the bind will be used, if we know it

Returns

stringthe bind name

Build the SQL text that using the binds

buildSQL() : string
Inherited

Returns

stringthe SQL text

Link another SqlBindField to this bindFields.

linkBindsOf(\salt\SqlBindField $other, string $source = \salt\ClauseType::ALL, string $otherSource = \salt\ClauseType::ALL
Inherited

Parameters

$other

\salt\SqlBindField

the other SqlBindField to link

$source

string

clause usage of the SqlBindField if we known it

$otherSource

string

restrict link to this source in $other

Exceptions

\salt\SaltException if this SqlBindField is already resolved

Remove binds (local and linked) of the specified source.

removeBinds(string $source) 
Inherited

Parameters

$source

string

ClauseType of specific text

Used for replace something that can be a value by a bind or a SQL text

resolveFieldName(string $source, mixed|\salt\SqlExpr $fieldNameOrValue, mixed|\salt\SqlExpr $fieldOfValue = NULL) : string | array<mixed,string>

Parameters

$source

string

caller of resolve : ClauseType or specific text

$fieldNameOrValue

mixed\salt\SqlExpr

a FieldName (string) or SqlExpr or potential value (int, string, array) if 3rd argument is provided

$fieldOfValue

mixed\salt\SqlExpr

a Field related to the value. Can be a SqlExpr or a string. Can be NULL if 2nd argument is a string fieldName

Returns

stringarray<mixed,string>absolute field name (alias.fieldname) or string with bind values or array of bind values if 2nd argument is an array of values

Throw an exception if called after SqlBind have been resolved

checkNotResolved() 
Inherited

Exceptions

\salt\SaltException if called after toSQL()

Get the type of the field

getFieldType(string $field) : integer

Parameters

$field

string

the fieldName

Returns

integerFiedType type of the field

 Properties

 

the object the query is build for

$_salt_obj : \salt\Base

Default

 

bind unique number

$_salt_bindNumber : integer

Default

0
Static
 

bind pagination unique number

$_salt_bindPaginationNumber : integer

Default

0
Static
 

list of binds

$_salt_binds : array<mixed,mixed>

Default

array()
content
array of bindName => array(
					'value' => mixed // value of bind
					'type' => int FieldType // type of field
					'private' => boolean // if value is private data (like passwords)
			)
 

FALSE for never execute the query

$_salt_enabled : boolean

Default

TRUE
 

list of linked binds

$_salt_others : array<mixed,\salt\SqlBindField[][]>

Default

array()
content
array of (ClauseType (source) => array of ClauseType(dest) => array of SqlBindField)
 

TRUE if binds values are private (do not display in debug queries)

$_salt_privateBinds : boolean

Default

FALSE
 

list of local binds by source

$_salt_sources : array<mixed,string[]>

Default

array()
content
array of (ClauseType => array of bindName)
 

SQL text that use the binds

$_salt_text : string

Default

NULL