Construct a complex SQL expression

package salt\sql
inherited_from \salt\SqlBindField

 Methods

Set the SqlExpr type to BOOLEAN

asBoolean() : \salt\SqlExpr

Returns

\salt\SqlExprcurrent object

Set the SqlExpr type to DATE

asDate(string $format = NULL) : \salt\SqlExpr

Parameters

$format

string

format of the source, used for convert to date.

Exceptions

\Exception

Returns

\salt\SqlExprcurrent object

Set the SqlExpr type to NUMBER

asNumber() : \salt\SqlExpr

Returns

\salt\SqlExprcurrent object

Set the SqlExpr type to the field type

asSetter(\salt\Field $field) : \salt\SqlExpr

Parameters

$field

\salt\Field

the field to use for configure SqlExpr

Returns

\salt\SqlExprcurrent object

Set the SqlExpr type to TEXT

asText() : \salt\SqlExpr

Returns

\salt\SqlExprcurrent object

Set the SqlExpr type to DATE, as TIMESTAMP format

asTimestamp(string $format = NULL) : \salt\SqlExpr

Parameters

$format

string

format of the source, used for convert to date.

Exceptions

\Exception

Returns

\salt\SqlExprcurrent object

Add DISTINCT before SqlExpr

distinct() : \salt\SqlExpr

Returns

\salt\SqlExprcurrent object

Create a new SqlExpr for a field

field(string $alias, \salt\Field $field) : \salt\SqlExpr
Static

Do not use this method, but Query::getField($fieldName) instead

Parameters

$alias

string

alias of the table of the field

$field

\salt\Field

field

Returns

\salt\SqlExpr

Create a new SqlExpr for an SQL function

func(string $name, \salt\SqlExpr $args = NULL) : \salt\SqlExpr
Static

Parameters

$name

string

name of the function

$args

\salt\SqlExpr

... $args list of function arguments.

Returns

\salt\SqlExpr

Retrieve all used table alias in SqlExpr

getAllUsedTableAlias() : array<mixed,string>

Returns

array<mixed,string>all table alias

Return all binds

getBinds() 
see
inherited_from \salt\SqlBindField::getBinds()

Return all binds

getBinds() : array<mixed,mixed[]>
Inherited

Returns

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

Retrieve the field name of a FIELD type SqlExpr

getFieldName() : string

Returns

stringthe field name if SqlExpr is a FIELD expr, NULL otherwise

Get the type of the SqlExpr

getType() : integer

Returns

integerFieldType the type of the SqlExpr

Add NOT before SqlExpr

not() : \salt\SqlExpr

Returns

\salt\SqlExprcurrent object

Increment or decrement a field

plus(integer $value = 1) : \salt\SqlExpr

Parameters

$value

integer

value to increment (if positive) or decrement (if negative)

Returns

\salt\SqlExprcurrent object

Use a template to format SqlExpr

template(string $template, array<mixed,\salt\SqlExpr> $args = array()) : \salt\SqlExpr

Parameters

$template

string

template with TEMPLATE_MAIN and TEMPLATE_PARAM if necessary

$args

array<mixed,\salt\SqlExpr>

list of parameters

Returns

\salt\SqlExprcurrent object

Change in objet after calling this method are ignored

toSQL() : string

Returns

stringthe SQL text for SqlExpr

Create a new SqlExpr for a value

value(mixed $value) : \salt\SqlExpr
Static

Parameters

$value

mixed

value to transform in SqlExpr. Can be NULL

Returns

\salt\SqlExpr

create a new SqlExr. Use static function for that

__construct(integer $objectType, mixed $data) 

Parameters

$objectType

integer

type of SqlExpr : FUNC|VALUE|FIELD

$data

mixed

source of SqlExpr, can be a scalar value or an array

Add a bind

addBind(mixed $value, integer $type) : string
Inherited

Parameters

$value

mixed

value of bind

$type

integer

(FieldType) type of the field

Returns

stringthe bind name

Convert a SQL date to another format

getTemplateForConvertSqlDate(string $origin, string $destination) : string

Parameters

$origin

string

origin date format

$destination

string

destination date format

Returns

stringtemplate for conversion, with ? as placeholder

 Properties

 

bind unique number

$bindNumber : integer

Default

0
Static
 

list of binds

$binds : array<mixed,mixed>

Default

array()
content
array of bindName => array(
					'value' => mixed // value of bind
					'type' => int FieldType // type of field
			)
 

source of SqlExpr, can be a string, int, array, etc...

$data : mixed

Default

NULL
 

format of the parameter of the SqlExpr, when it's a DATE

$dateFormat : string

Default

NULL
 

type of SqlExpr : FUNC|VALUE|FIELD

$objectType : integer

Default

NULL
 

field to use when SqlExpr is in a SET clause

$setter : \salt\Field

Default

NULL
 

memoized value of toSql() function

$sqlText : string

Default

NULL
 

the template to apply

$template : array<mixed,string>

Default

array()
content array of (template, param1, param2, ...)
 

TRUE if the date SqlExpr have to be converted in TIMESTAMP, FALSE for MySQL DATE. Not used if the SqlExpr is not a date

$timestamp : boolean

Default

FALSE
 

type of the return of SqlExpr : FieldType::*

$type : integer

Default

NULL

 Constants

 

type of SqlExpr : a field

FIELD = 2 
 

type of SqlExpr : a function

FUNC = 0 
 

template replaced by the main source of SqlExpr

TEMPLATE_MAIN = "\1:main\2" 
 

template replaced by each parameters in order

TEMPLATE_PARAM = "\3?\4" 
 

type of SqlExpr : a value

VALUE = 1