Dotclear 2.24
Loading...
Searching...
No Matches
dcSqlStatement Class Reference
Inheritance diagram for dcSqlStatement:
dcDeleteStatement dcInsertStatement dcJoinStatement dcSelectStatement dcTruncateStatement dcUpdateStatement

Public Member Functions

 __construct ()
 
 __get (string $property)
 
 __set (string $property, $value)
 
 __isset (string $property)
 
 __unset (string $property)
 
 __invoke ()
 
 statement ()
 
 columns ($c, bool $reset=false)
 
 fields ($c, bool $reset=false)
 
 column ($c, bool $reset=false)
 
 field ($c, bool $reset=false)
 
 from ($c, bool $reset=false, bool $first=false)
 
 where ($c, bool $reset=false)
 
 on ($c, bool $reset=false)
 
 cond ($c, bool $reset=false)
 
 and ($c, bool $reset=false)
 
 andGroup ($c)
 
 or ($c, bool $reset=false)
 
 orGroup ($c)
 
 sql ($c, bool $reset=false)
 
 escape (string $value)
 
 quote ($value, bool $escape=true)
 
 alias (string $name, string $alias)
 
 as (string $name, string $alias)
 
 in ($list, string $cast='')
 
 inSelect (string $field, dcSelectStatement $sql)
 
 dateFormat (string $field, string $pattern)
 
 like (string $field, string $pattern)
 
 regexp (string $value)
 
 unique (string $field)
 
 count (string $field, ?string $as=null, bool $unique=false)
 
 avg (string $field, ?string $as=null)
 
 max (string $field, ?string $as=null)
 
 min (string $field, ?string $as=null)
 
 sum (string $field, ?string $as=null)
 
 isNull (string $field)
 
 isNotNull (string $field)
 
 isSame (string $local, string $external)
 
 compare (string $external, bool $trigger_error=false, bool $dump=false, bool $print=false)
 

Protected Attributes

const VERBOSE_SQL_ALIAS = false
 
 $con
 
 $syntax
 
 $_AS = ' '
 
 $columns = []
 
 $from = []
 
 $where = []
 
 $cond = []
 
 $sql = []
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Class constructor

Reimplemented in dcSelectStatement, dcJoinStatement, dcUpdateStatement, and dcInsertStatement.

References dcCore\app().

Member Function Documentation

◆ __get()

__get ( string  $property)

Magic getter method

Parameters
string$propertyThe property
Returns
mixed property value if property exists

◆ __set()

__set ( string  $property,
  $value 
)

Magic setter method

Parameters
string$propertyThe property
mixed$valueThe value
Returns
mixed self instance, enabling to chain calls

◆ __isset()

__isset ( string  $property)

Magic isset method

Parameters
string$propertyThe property
Returns
bool

◆ __unset()

__unset ( string  $property)

Magic unset method

Parameters
string$propertyThe property

◆ __invoke()

__invoke ( )

Magic invoke method

Alias of statement()

Returns
string

References statement().

◆ statement()

statement ( )

Returns a SQL dummy statement

Returns
string the statement

Reimplemented in dcSelectStatement, dcJoinStatement, dcDeleteStatement, dcUpdateStatement, dcInsertStatement, and dcTruncateStatement.

Referenced by __invoke(), and compare().

◆ columns()

columns (   $c,
bool  $reset = false 
)

Adds column(s)

Parameters
mixed$cthe column(s)
boolean$resetreset previous column(s) first
Returns
mixed self instance, enabling to chain calls

References columns().

Referenced by column(), columns(), fields(), dcSelectStatement\statement(), and dcInsertStatement\statement().

◆ fields()

fields (   $c,
bool  $reset = false 
)

columns() alias

Parameters
mixed$cthe column(s)
boolean$resetreset previous column(s) first
Returns
mixed self instance, enabling to chain calls

References columns().

◆ column()

column (   $c,
bool  $reset = false 
)

columns() alias

Parameters
mixed$cthe column(s)
boolean$resetreset previous column(s) first
Returns
mixed self instance, enabling to chain calls

References columns().

Referenced by field().

◆ field()

field (   $c,
bool  $reset = false 
)

column() alias

Parameters
mixed$cthe column(s)
boolean$resetreset previous column(s) first
Returns
mixed self instance, enabling to chain calls

References column().

◆ from()

from (   $c,
bool  $reset = false,
bool  $first = false 
)

Adds FROM clause(s)

Parameters
mixed$cthe from clause(s)
boolean$resetreset previous from(s) first
boolean$firstput the from clause(s) at top of list
Returns
mixed self instance, enabling to chain calls

References from().

Referenced by from(), dcInsertStatement\into(), dcUpdateStatement\ref(), dcUpdateStatement\reference(), dcSelectStatement\statement(), dcJoinStatement\statement(), dcDeleteStatement\statement(), dcUpdateStatement\statement(), dcInsertStatement\statement(), and dcTruncateStatement\statement().

◆ where()

where (   $c,
bool  $reset = false 
)

Adds WHERE clause(s) condition (each will be AND combined in statement)

Parameters
mixed$cthe clause(s)
boolean$resetreset previous where(s) first
Returns
mixed self instance, enabling to chain calls

References where().

Referenced by dcAuth\checkUser(), on(), dcSelectStatement\statement(), dcJoinStatement\statement(), dcDeleteStatement\statement(), where(), and dcUpdateStatement\whereStatement().

◆ on()

on (   $c,
bool  $reset = false 
)

from() alias

Parameters
mixed$cthe clause(s)
boolean$resetreset previous where(s) first
Returns
mixed self instance, enabling to chain calls

References where().

◆ cond()

cond (   $c,
bool  $reset = false 
)

Adds additional WHERE clause condition(s) (including an operator at beginning)

Parameters
mixed$cthe clause(s)
boolean$resetreset previous condition(s) first
Returns
mixed self instance, enabling to chain calls

References cond().

Referenced by and(), cond(), or(), dcSelectStatement\statement(), dcJoinStatement\statement(), dcDeleteStatement\statement(), and dcUpdateStatement\whereStatement().

◆ and()

and (   $c,
bool  $reset = false 
)

Adds additional WHERE AND clause condition(s)

Parameters
mixed$cthe clause(s)
boolean$resetreset previous condition(s) first
Returns
mixed self instance, enabling to chain calls

References cond().

◆ andGroup()

andGroup (   $c)

Helper to group some AND parts

Parameters
mixed$cthe parts}
Returns
string

◆ or()

or (   $c,
bool  $reset = false 
)

Adds additional WHERE OR clause condition(s)

Parameters
mixed$cthe clause(s)
boolean$resetreset previous condition(s) first
Returns
mixed self instance, enabling to chain calls

References cond().

◆ orGroup()

orGroup (   $c)

Helper to group some OR parts

Parameters
mixed$cthe parts}
Returns
string

◆ sql()

sql (   $c,
bool  $reset = false 
)

Adds generic clause(s)

Parameters
mixed$cthe clause(s)
boolean$resetreset previous generic clause(s) first
Returns
mixed self instance, enabling to chain calls

References sql().

Referenced by sql(), dcSelectStatement\statement(), dcJoinStatement\statement(), dcDeleteStatement\statement(), and dcUpdateStatement\whereStatement().

◆ escape()

escape ( string  $value)

Escape a value

Parameters
string$valueThe value
Returns
string

Referenced by regexp().

◆ quote()

quote (   $value,
bool  $escape = true 
)

Quote and escape a value if necessary (type string)

Parameters
mixed$valueThe value
boolean$escapeThe escape
Returns
string

Referenced by like().

◆ alias()

alias ( string  $name,
string  $alias 
)

Return a SQL table/column fragment using an alias for a name

Parameters
string$nameThe name (table, field)
string$aliasThe alias
Returns
string

Referenced by as().

◆ as()

as ( string  $name,
string  $alias 
)

alias() alias

References alias().

Referenced by isSame(), and dcInsertStatement\statement().

◆ in()

in (   $list,
string  $cast = '' 
)

Return an SQL IN (…) fragment

Parameters
mixed$listThe list of values
string$castCast given not null values to specified type
Returns
string

◆ inSelect()

inSelect ( string  $field,
dcSelectStatement  $sql 
)

Return an SQL IN (SELECT …) fragment

Parameters
string$fieldThe field
dcSelectStatement$sqlThe sql
Returns
string

References $sql.

◆ dateFormat()

dateFormat ( string  $field,
string  $pattern 
)

Return an SQL formatted date

Parameters
string$fieldField name
string$patternDate format
Returns
string

◆ like()

like ( string  $field,
string  $pattern 
)

Return an SQL formatted like

Parameters
string$fieldThe field
string$patternThe pattern
Returns
string

References quote().

◆ regexp()

regexp ( string  $value)

Return an SQL formatted REGEXP clause

Parameters
string$valueThe value
Returns
string

References escape().

◆ unique()

unique ( string  $field)

Return an DISTINCT clause

Parameters
string$fieldThe field
Returns
string

Referenced by count().

◆ count()

count ( string  $field,
?string  $as = null,
bool  $unique = false 
)

Return an COUNT(…) clause

Parameters
string$fieldThe field
null | string$asOptional alias
bool$uniqueUnique values only
Returns
string

References unique().

Referenced by dcSelectStatement\statement(), dcJoinStatement\statement(), dcDeleteStatement\statement(), dcUpdateStatement\statement(), dcInsertStatement\statement(), dcTruncateStatement\statement(), and dcUpdateStatement\whereStatement().

◆ avg()

avg ( string  $field,
?string  $as = null 
)

Return an AVG(…) clause

Parameters
string$fieldThe field
null | string$asOptional alias
Returns
string

◆ max()

max ( string  $field,
?string  $as = null 
)

Return an MAX(…) clause

Parameters
string$fieldThe field
null | string$asOptional alias
Returns
string

◆ min()

min ( string  $field,
?string  $as = null 
)

Return an MIN(…) clause

Parameters
string$fieldThe field
null | string$asOptional alias
Returns
string

◆ sum()

sum ( string  $field,
?string  $as = null 
)

Return an SUM(…) clause

Parameters
string$fieldThe field
null | string$asOptional alias
Returns
string

◆ isNull()

isNull ( string  $field)

Return an IS NULL clause

Parameters
string$fieldThe field
Returns
string

◆ isNotNull()

isNotNull ( string  $field)

Return an IS NOT NULL clause

Parameters
string$fieldThe field
Returns
string

◆ isSame()

isSame ( string  $local,
string  $external 
)

Compare two SQL queries

May be used for debugging purpose as:

if (!$sql->isSame($sql->statement(), $strReq)) { trigger_error('SQL statement error: ' . $sql->statement() . ' / ' . $strReq, E_USER_ERROR); }

Parameters
string$localThe local
string$externalThe external
Returns
boolean True if same, False otherwise.

References as().

Referenced by compare().

◆ compare()

compare ( string  $external,
bool  $trigger_error = false,
bool  $dump = false,
bool  $print = false 
)

Compare local statement and external one

Parameters
string$externalThe external
bool$trigger_errorTrue to trigger an error if compare failsl
bool$dumpTrue to var_dump() all if compare fails
bool$printTrue to print_r() all if compare fails
Returns
bool

References isSame(), and statement().

Field Documentation

◆ VERBOSE_SQL_ALIAS

const VERBOSE_SQL_ALIAS = false
protected

◆ $con

$con
protected

DB handle

◆ $syntax

$syntax
protected

◆ $_AS

$_AS = ' '
protected

◆ $columns

$columns = []
protected

◆ $from

$from = []
protected

◆ $where

$where = []
protected

◆ $cond

$cond = []
protected

◆ $sql


The documentation for this class was generated from the following file: