Orion PHP  0.11.12
The PHP5.3 framework
Orion\Core\Query\Sql Class Reference
+ Inheritance diagram for Orion\Core\Query\Sql:

List of all members.

Public Member Functions

 __construct ($model)
andWhere ($field, $comparator=null, $value=null)
delete ()
distinct ()
 fetch ()
 fetchAll ()
groupBy ($col)
groupConcat ($field, $name, $separator, $table=null)
join ($link, $fields, $type='LEFT')
joinTable ($table, $leftfield, $rightfield, $type='LEFT')
limit ($size)
manualWhere ($clause)
offset ($start)
order ($fields, $mode)
orWhere ($field, $comparator=null, $value=null)
save ()
select ($data=null)
selectAllExcept ($data=null)
set ($key, $value)
 success ()
update ()
where ($field, $comparator=null, $value=null)
 tablePrefix ($fields, $force=false, $table=null)
 antiQuote ($data)
 escape ($data)
execute ($type=null)
 quote ($string)
 getTable ()
 getLastJoinedTable ()
setTable ($table)
unsetTable ($dontUseModel=false)
 hasModel ()
 getQuery ()

Public Attributes

const L_FIELD_SLUG = 'linkedfield_'
const L_FIELD_SEP = '__'

Protected Member Functions

 parseJoinFields (&$object)

Protected Attributes

 $_TABLE = null
 $_COLUMNS = array( )
 $_KEYS = null
 $_VALUES = null
 $_SETS = null
 $_DISTINCT = false
 $_WHERE = array( )
 $_MWHERE = null
 $_AWHERE = array( )
 $_OWHERE = array( )
 $_ORDER = array( )
 $_LIMIT = null
 $_GROUPBY = null
 $_OFFSET = null
 $_TYPE = null
 $_JOIN = array( )
 $_JOIN_COLUMNS = array( )
 $_JOIN_TABLE = array()
 $_QUERY = null
 $_QUERY_STRING = null
 $_RESULT = null
 $_PDO = null
 $_LAST_JOINED_TABLE = null

Static Private Attributes

static $COMPARATORS
static $ORDERS

Detailed Description

Orion Query for SQL DB type.

Author:
Thibaut Despoulain BSD 4-clauses
Version:
0.11.10

Definition at line 17 of file sql.php.


Constructor & Destructor Documentation

Orion\Core\Query\Sql::__construct ( model)

Implements Orion\Core\Query\Base.

Definition at line 189 of file sql.php.


Member Function Documentation

& Orion\Core\Query\Sql::andWhere ( field,
comparator = null,
value = null 
)

Query chain element, defining AND where clause

Parameters:
string$field
string$comparator
mixed$valueIf no wildcard should be used, pass this parameter using Tools::escapeSql($value). Other standard quotes escapes are done internally.

Implements Orion\Core\Query\Base.

Definition at line 205 of file sql.php.

Orion\Core\Query\Sql::antiQuote ( data)

Surrround a string with antiquotes

Parameters:
String$data
Returns:
String

Definition at line 668 of file sql.php.

& Orion\Core\Query\Sql::delete ( )

Implements Orion\Core\Query\Base.

Definition at line 227 of file sql.php.

& Orion\Core\Query\Sql::distinct ( )

Ignore duplicates on provided field

Parameters:
String$field

Definition at line 236 of file sql.php.

Orion\Core\Query\Sql::escape ( data)

Escapes string for mysql usage ('\', "\0", "\n", "\r", "'", '"', "\x1a")

Parameters:
string$data
string[]$custom An array of custom elements to remove
Returns:
string

Implements Orion\Core\Query\Base.

Definition at line 691 of file sql.php.

& Orion\Core\Query\Sql::execute ( type = null)

Execute given query type using current query data

Parameters:
string$typeQuery type ('insert', 'delete', ..etc)
Returns:
Sql

Definition at line 713 of file sql.php.

Orion\Core\Query\Sql::fetch ( )

Ends a query chain and returns the resulting row

Returns:

Implements Orion\Core\Query\Base.

Definition at line 246 of file sql.php.

Orion\Core\Query\Sql::fetchAll ( )

Ends a query chain and returns the resulting rows

Returns:
[]

Implements Orion\Core\Query\Base.

Definition at line 274 of file sql.php.

Orion\Core\Query\Sql::getLastJoinedTable ( )

Get last joined table's name

Returns:
string

Definition at line 746 of file sql.php.

Orion\Core\Query\Sql::getQuery ( )

Get current query string

Returns:
string current query string

Definition at line 799 of file sql.php.

Orion\Core\Query\Sql::getTable ( )

Get current table in use

Returns:
String

Definition at line 737 of file sql.php.

& Orion\Core\Query\Sql::groupBy ( col)

Add a GROUP BY statement on provided field

Parameters:
String$col

Definition at line 302 of file sql.php.

& Orion\Core\Query\Sql::groupConcat ( field,
name,
separator,
table = null 
)

This method is SQL-only. Groups rows from x-to-many query by concatenating them in a sigle column.

Parameters:
String$fieldThe joined column to contact
String$nameThe alias of the new column
String$separatorThe separator used for concatenation
String[$table] The table used to prefix the $field

Definition at line 317 of file sql.php.

Orion\Core\Query\Sql::hasModel ( )

Is a model bound to Query object ?

Returns:
Boolean

Definition at line 790 of file sql.php.

& Orion\Core\Query\Sql::join ( link,
fields,
type = 'LEFT' 
)

Query chain element, joining provided $fields on $link. This method is only usable with Query that have a model bound width linked fields. For manual joints, use manualJoin().

Parameters:
string$linkEither a linked field name if Query is bound to a Model or a table name otherwise.
string$fieldsThe fields to join
string$type[LEFT|RIGHT|INNER|OUTER]

Implements Orion\Core\Query\Base.

Definition at line 332 of file sql.php.

& Orion\Core\Query\Sql::joinTable ( table,
leftfield,
rightfield,
type = 'LEFT' 
)

/!\ This method is experimental and should be used only if you know what you are doing. Query chain element, joining provided $table to the query. This method does not require a bound model. But the downside is that you won't have any object formating or column aliasing, so be careful with overlaps.

Parameters:
string$linkA table name.
string$leftfieldThe field from the current table
string$rightfieldThe field from the joined table
string$type[LEFT|RIGHT|INNER|OUTER]

Definition at line 374 of file sql.php.

& Orion\Core\Query\Sql::limit ( size)

Query chain element, limiting the query to a given $size

Parameters:
Integer$size

Implements Orion\Core\Query\Base.

Definition at line 391 of file sql.php.

& Orion\Core\Query\Sql::manualWhere ( clause)

Query chain element, defining where clause manualy. Used for complex where clauses

Be careful when using manual where clause because the string is not parsed, nor escaped. It is used in the query 'AS IS'.

Parameters:
stringthe complete where clause, without the WHERE keyword

Implements Orion\Core\Query\Base.

Definition at line 406 of file sql.php.

& Orion\Core\Query\Sql::offset ( start)

Query chain element, setting the starting offset

Parameters:
int$start

Implements Orion\Core\Query\Base.

Definition at line 420 of file sql.php.

& Orion\Core\Query\Sql::order ( fields,
mode 
)

Query chain element, setting ordering clause

Parameters:
mixed$fieldseither an array of fields or a single field
string$mode'ASC'|'DESC' or an array of modes

Implements Orion\Core\Query\Base.

Definition at line 435 of file sql.php.

& Orion\Core\Query\Sql::orWhere ( field,
comparator = null,
value = null 
)

Query chain element, defining OR where clause

Parameters:
string$field
string$comparator
mixed$valueIf no wildcard should be used, pass this parameter using Tools::escapeSql($value). Other standard quotes escapes are done internally.

Implements Orion\Core\Query\Base.

Definition at line 480 of file sql.php.

Orion\Core\Query\Sql::parseJoinFields ( &$  object) [protected]

Parse query-resulting object to build linked objects from joined fields' syntax.
In other words, convert "L_FIELD_SLUG.$linkedfield.L_FIELD_SEP.$fieldname" into linked Object.

Parameters:
\Orion\Core\Model|\Orion\Core\Object

Definition at line 936 of file sql.php.

Orion\Core\Query\Sql::quote ( string)

Adds single quotes to a string

Parameters:
stirng$string
Returns:
string

Definition at line 728 of file sql.php.

& Orion\Core\Query\Sql::save ( )

Implements Orion\Core\Query\Base.

Definition at line 502 of file sql.php.

& Orion\Core\Query\Sql::select ( data = null)

Start a select query chain

Parameters:
mixedEither select('f1','f2', ...) or select(array('f1','f2',...))

Implements Orion\Core\Query\Base.

Definition at line 511 of file sql.php.

& Orion\Core\Query\Sql::selectAllExcept ( data = null)

Start a select query chain by selecting all fields of a model except those provided. Can only be used on Query with a model bound.

Parameters:
mixed$dataEither selectAllExcept('f1','f2', ...) or selectAllExcept(array('f1','f2',...))

Implements Orion\Core\Query\Base.

Definition at line 540 of file sql.php.

& Orion\Core\Query\Sql::set ( key,
value 
)

Set columns values for insert and update queries

Parameters:
string$key
string$value
Returns:
Sql

Implements Orion\Core\Query\Base.

Definition at line 575 of file sql.php.

& Orion\Core\Query\Sql::setTable ( table)

Overrides current table name.

Parameters:
String$table

Implements Orion\Core\Query\Base.

Definition at line 755 of file sql.php.

Orion\Core\Query\Sql::success ( )

Definition at line 589 of file sql.php.

Orion\Core\Query\Sql::tablePrefix ( fields,
force = false,
table = null 
)

Add a table prefix to a field name or an array of field names if they do not already have a table prefix. Also add surrounding antiquotes.

Parameters:
String|String[]$field field name
Boolean$forceForce prefix, even if field is already prefixed
String$tablePrefix with a custom table name instead of the current table.
Returns:
String prefixed field name

Definition at line 632 of file sql.php.

& Orion\Core\Query\Sql::unsetTable ( dontUseModel = false)

Revert table name back to model's table. Usable only on Query with a bound Model.

Parameters:
Boolean$dontUseModelSet this to TRUE to skip revert and force table to none

Definition at line 770 of file sql.php.

& Orion\Core\Query\Sql::update ( )

Implements Orion\Core\Query\Base.

Definition at line 594 of file sql.php.

& Orion\Core\Query\Sql::where ( field,
comparator = null,
value = null 
)

Query chain element, defining where clause

Parameters:
string$field
string$comparator
mixed$valueIf no wildcard should be used, pass this parameter using Tools::escapeSql($value). Other standard quotes escapes are done internally.

Implements Orion\Core\Query\Base.

Definition at line 605 of file sql.php.


Member Data Documentation

Orion::Core::Query\Sql::$_AWHERE = array( ) [protected]

Definition at line 98 of file sql.php.

Orion::Core::Query\Sql::$_COLUMNS = array( ) [protected]

Definition at line 55 of file sql.php.

Orion::Core::Query\Sql::$_DISTINCT = false [protected]

Definition at line 79 of file sql.php.

Orion::Core::Query\Sql::$_GROUPBY = null [protected]

Definition at line 122 of file sql.php.

Orion::Core::Query\Sql::$_JOIN = array( ) [protected]

Definition at line 140 of file sql.php.

Orion::Core::Query\Sql::$_JOIN_COLUMNS = array( ) [protected]

Definition at line 147 of file sql.php.

Orion::Core::Query\Sql::$_JOIN_TABLE = array() [protected]

Definition at line 153 of file sql.php.

Orion::Core::Query\Sql::$_KEYS = null [protected]

Definition at line 61 of file sql.php.

Orion::Core::Query\Sql::$_LAST_JOINED_TABLE = null [protected]

Definition at line 183 of file sql.php.

Orion::Core::Query\Sql::$_LIMIT = null [protected]

Definition at line 116 of file sql.php.

Orion::Core::Query\Sql::$_MWHERE = null [protected]

Definition at line 92 of file sql.php.

Orion::Core::Query\Sql::$_OFFSET = null [protected]

Definition at line 128 of file sql.php.

Orion::Core::Query\Sql::$_ORDER = array( ) [protected]

Definition at line 110 of file sql.php.

Orion::Core::Query\Sql::$_OWHERE = array( ) [protected]

Definition at line 104 of file sql.php.

Orion::Core::Query\Sql::$_PDO = null [protected]

Definition at line 177 of file sql.php.

Orion::Core::Query\Sql::$_QUERY = null [protected]

Definition at line 159 of file sql.php.

Orion::Core::Query\Sql::$_QUERY_STRING = null [protected]

Definition at line 165 of file sql.php.

Orion::Core::Query\Sql::$_RESULT = null [protected]

Definition at line 171 of file sql.php.

Orion::Core::Query\Sql::$_SETS = null [protected]

Definition at line 73 of file sql.php.

Orion::Core::Query\Sql::$_TABLE = null [protected]

Definition at line 49 of file sql.php.

Orion::Core::Query\Sql::$_TYPE = null [protected]

Definition at line 134 of file sql.php.

Orion::Core::Query\Sql::$_VALUES = null [protected]

Definition at line 67 of file sql.php.

Orion::Core::Query\Sql::$_WHERE = array( ) [protected]

Definition at line 85 of file sql.php.

Orion::Core::Query\Sql::$COMPARATORS [static, private]
Initial value:
 array(
        Core\Query::EQUAL => ' = ',
        Core\Query::NEQUAL => ' != ',
        Core\Query::LIKE => ' LIKE ',
        Core\Query::NOT => ' NOT ',
        Core\Query::REGEX => ' REGEXP '
    )

Definition at line 31 of file sql.php.

Orion::Core::Query\Sql::$ORDERS [static, private]
Initial value:
 array(
        Core\Query::ASCENDING => 'ASC',
        Core\Query::DESCENDING => 'DESC'
    )

Definition at line 38 of file sql.php.

const Orion::Core::Query\Sql::L_FIELD_SEP = '__'

Alias separator for JOIN queries. See L_FIELD_SLUG

Definition at line 29 of file sql.php.

const Orion::Core::Query\Sql::L_FIELD_SLUG = 'linkedfield_'

Slug used to alias joined fields in JOIN queries to ease object conversion in SELECT queries.
ie: A valid alias should look like : L_FIELD_SLUG . $fieldlink . L_FIELD_SEP . $fieldname
With $fieldlink, the name of the field usef for linkage and $fieldname the joined field.

Definition at line 24 of file sql.php.


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