Abstract Class xPDOQuery

Description

An xPDOCriteria derivative with methods for constructing complex statements.

  • abstract:

Located in /om/xpdoquery.class.php (line 35)

xPDOCriteria
   |
   --xPDOQuery
Direct descendents
Class Description
 class xPDOQuery_mysql An implementation of xPDOQuery for the MySQL database engine.
 class xPDOQuery_sqlite An implementation of xPDOQuery for the SQLite database engine.
 class xPDOQuery_sqlsrv An implementation of xPDOQuery for the sqlsrv database driver.
Class Constant Summary
 SQL_AND = 'AND'
 SQL_JOIN_CROSS = 'JOIN'
 SQL_JOIN_LEFT = 'LEFT JOIN'
 SQL_JOIN_NATURAL_LEFT = 'NATURAL LEFT JOIN'
 SQL_JOIN_NATURAL_RIGHT = 'NATURAL RIGHT JOIN'
 SQL_JOIN_RIGHT = 'RIGHT JOIN'
 SQL_JOIN_STRAIGHT = 'STRAIGHT_JOIN'
 SQL_OR = 'OR'
Variable Summary
 mixed $graph
 mixed $query
 mixed $_alias
 mixed $_class
 array $_operators
 mixed $_quotable
Method Summary
 xPDOQuery __construct ( &$xpdo,  $class, [ $criteria = null])
 void andCondition ( $conditions, [ $binding = null], [ $group = 0])
 xPDOQuery bindGraph (mixed $graph)
 void bindGraphNode (string $parentClass, string $parentAlias, string $classAlias, array $relations)
 string buildConditionalClause (array $conditions, [ &$conjunction = xPDOQuery::SQL_AND], [boolean $isFirst = true], string $conjunction)
 xPDOQuery command ([string $command = 'SELECT'])
 xPDOQuery condition ( &$target, [mixed $conditions = '1'], [string $conjunction = xPDOQuery::SQL_AND], [mixed $binding = null], [integer $condGroup = 0], string $target)
 boolean construct ()
 xPDOQuery from (string $class, [string $alias = ''])
 void getAlias ()
 void getClass ()
 xPDOQuery groupby (string $column, [string $direction = ''])
 void having ( $conditions)
 array hydrateGraph (array $rows, [ $cacheFlag = true])
 void hydrateGraphNode ( &$row,  &$instance, string $alias, array $relations, array $row, xPDOObject $instance)
 void hydrateGraphParent ( &$instances,  $row)
 void innerJoin ( $class, [ $alias = ''], [ $conditions = array ()], [ $conjunction = xPDOQuery::SQL_AND], [ $binding = null], [ $condGroup = 0])
 boolean isConditionalClause (string $string)
 xPDOQuery join (string $class, [string $alias = ''], [string $type = xPDOQuery::SQL_JOIN_CROSS], [mixed $conditions = array ()], [string $conjunction = xPDOQuery::SQL_AND], [array $binding = null], [int $condGroup = 0])
 void leftJoin ( $class, [ $alias = ''], [ $conditions = array ()], [ $conjunction = xPDOQuery::SQL_AND], [ $binding = null], [ $condGroup = 0])
 xPDOQuery limit (integer $limit, [integer $offset = 0])
 void orCondition ( $conditions, [ $binding = null], [ $group = 0])
 void parseConditions (mixed $conditions, [string $conjunction = xPDOQuery::SQL_AND])
 xPDOStatement prepare ([ $bindings = array ()], [ $byValue = true], [ $cacheFlag = null])
 void rightJoin ( $class, [ $alias = ''], [ $conditions = array ()], [ $conjunction = xPDOQuery::SQL_AND], [ $binding = null], [ $condGroup = 0])
 xPDOQuery select ([string $columns = '*'])
 xPDOQuery setClassAlias ([string $alias = ''])
 xPDOQuery sortby (string $column, [string $direction = 'ASC'])
 xPDOQuery where ([mixed $conditions = ''], [string $conjunction = xPDOQuery::SQL_AND], [mixed $binding = null], [integer $condGroup = 0])
 void wrap (xPDOCriteria $criteria)
Variables
mixed $graph = array () (line 83)
  • access: public
mixed $query = array (
'command' => 'SELECT',
'distinct' => '',
'columns' => '',
'from' => array (
'tables' => array (),'joins'=>array(),),'where'=>array(),'groupby'=>array(),'having'=>array(),'orderby'=>array(),'offset'=>'','limit'=>'',)
(line 84)
  • access: public
mixed $_alias = null (line 82)
  • access: protected
mixed $_class = null (line 81)
  • access: protected
array $_operators = array (
'=',
'!=',
'<',
'<=',
'>',
'>=',
'<=>',
' LIKE ',
' IS NULL',
' IS NOT NULL',
' BETWEEN ',
' IN ',
' IN(',
' NOT(',
' NOT (',
' NOT IN ',
' NOT IN(',
' EXISTS (',
' EXISTS(',
' NOT EXISTS (',
' NOT EXISTS(',
' COALESCE(',
' GREATEST(',
' INTERVAL(',
' LEAST(',
'MATCH(',
'MATCH ('
)
(line 51)

An array of symbols and keywords indicative of SQL operators.

  • todo: Refactor this to separate xPDOQuery operators from db-specific conditional statement identifiers.
  • access: protected
mixed $_quotable = array ('string', 'password', 'date', 'datetime', 'timestamp', 'time') (line 80)
  • access: protected

Inherited Variables

Inherited from xPDOCriteria

xPDOCriteria::$bindings
xPDOCriteria::$cacheFlag
xPDOCriteria::$sql
xPDOCriteria::$stmt
Methods
Constructor __construct (line 100)
  • access: public
xPDOQuery __construct ( &$xpdo,  $class, [ $criteria = null])
  • &$xpdo
  • $class
  • $criteria

Redefinition of:
xPDOCriteria::__construct()
The constructor for a new xPDOCriteria instance.

Redefined in descendants as:
andCondition (line 288)
  • access: public
void andCondition ( $conditions, [ $binding = null], [ $group = 0])
  • $conditions
  • $binding
  • $group
bindGraph (line 345)

Bind an object graph to the query.

xPDOQuery bindGraph (mixed $graph)
  • mixed $graph: An array or JSON graph of related objects.
bindGraphNode (line 378)

Bind the node of an object graph to the query.

  • access: public
void bindGraphNode (string $parentClass, string $parentAlias, string $classAlias, array $relations)
  • string $parentClass: The class representing the relation parent.
  • string $parentAlias: The alias the class is assuming.
  • string $classAlias: The class representing the related graph node.
  • array $relations: Child relations of the current graph node.
buildConditionalClause (line 663)

Builds conditional clauses from xPDO condition expressions.

  • return: The conditional clause.
  • access: public
string buildConditionalClause (array $conditions, [ &$conjunction = xPDOQuery::SQL_AND], [boolean $isFirst = true], string $conjunction)
  • array $conditions
  • string $conjunction
  • boolean $isFirst: Indicates if this is the first condition in collection.
  • &$conjunction
command (line 138)

Set the type of SQL command you want to build.

The default is SELECT, though it also supports DELETE.

  • return: Returns the current object for convenience.
  • todo: Implement support for other standard SQL statements such as UPDATE.
  • access: public
xPDOQuery command ([string $command = 'SELECT'])
  • string $command: The type of SQL statement represented by this object. Default is 'SELECT'.
condition (line 267)

Add a condition to the query.

  • return: Returns the instance.
  • access: public
xPDOQuery condition ( &$target, [mixed $conditions = '1'], [string $conjunction = xPDOQuery::SQL_AND], [mixed $binding = null], [integer $condGroup = 0], string $target)
  • string $target: The target clause for the condition.
  • mixed $conditions: A valid xPDO criteria expression.
  • string $conjunction: The conjunction to use when appending this condition, i.e., AND or OR.
  • mixed $binding: A value or PDO binding representation of a value for the condition.
  • integer $condGroup: A numeric identifier for associating conditions into groups.
  • &$target
construct (line 482)

Constructs the SQL query from the xPDOQuery definition.

  • return: Returns true if a SQL statement was successfully constructed.
  • abstract:
  • access: public
boolean construct ()

Redefined in descendants as:
from (line 246)

Add a FROM clause to the query.

  • return: Returns the instance.
  • access: public
xPDOQuery from (string $class, [string $alias = ''])
  • string $class: The class representing the table to add.
  • string $alias: An optional alias for the class.
getAlias (line 124)
  • access: public
void getAlias ()
getClass (line 120)
  • access: public
void getClass ()
groupby (line 316)

Add an GROUP BY clause to the query.

  • return: Returns the instance.
  • access: public
xPDOQuery groupby (string $column, [string $direction = ''])
  • string $column: Column identifier to group by.
  • string $direction: The direction to sort by, ASC or DESC.
having (line 321)
  • access: public
void having ( $conditions)
  • $conditions
hydrateGraph (line 400)

Hydrates a graph of related objects from a single result set.

  • return: A collection of objects with all related objects from the graph pre-populated.
  • access: public
array hydrateGraph (array $rows, [ $cacheFlag = true])
  • array $rows: A collection of result set rows for hydrating the graph.
  • $cacheFlag
hydrateGraphNode (line 450)

Hydrates a node of the object graph.

  • access: public
void hydrateGraphNode ( &$row,  &$instance, string $alias, array $relations, array $row, xPDOObject $instance)
  • array $row: The result set representing the current node.
  • xPDOObject $instance: The xPDOObject instance to be hydrated from the node.
  • string $alias: The alias identifying the object in the parent relationship.
  • array $relations: Child relations of the current node.
  • &$row
  • &$instance
hydrateGraphParent (line 424)
  • access: public
void hydrateGraphParent ( &$instances,  $row)
  • &$instances
  • $row
innerJoin (line 227)
  • access: public
void innerJoin ( $class, [ $alias = ''], [ $conditions = array ()], [ $conjunction = xPDOQuery::SQL_AND], [ $binding = null], [ $condGroup = 0])
  • $class
  • $alias
  • $conditions
  • $conjunction
  • $binding
  • $condGroup
isConditionalClause (line 642)

Determines if a string contains a conditional operator.

  • return: True if the string is a complete conditional SQL clause.
  • access: public
boolean isConditionalClause (string $string)
  • string $string: The string to evaluate.
join (line 201)

Join a table represented by the specified class.

  • return: Returns the current object for convenience.
  • access: public
xPDOQuery join (string $class, [string $alias = ''], [string $type = xPDOQuery::SQL_JOIN_CROSS], [mixed $conditions = array ()], [string $conjunction = xPDOQuery::SQL_AND], [array $binding = null], [int $condGroup = 0])
  • string $class: The classname (or relation alias for aggregates and composites) of representing the table to be joined.
  • string $alias: An optional alias to represent the joined table in the constructed query.
  • string $type: The type of join to perform. See the xPDOQuery::SQL_JOIN constants.
  • mixed $conditions: Conditions of the join specified in any xPDO compatible criteria object or expression.
  • string $conjunction: A conjunction to be applied to the condition or conditions supplied.
  • array $binding: Optional bindings to accompany the conditions.
  • int $condGroup: An optional identifier for adding the conditions to a specific set of conjoined expressions.
leftJoin (line 231)
  • access: public
void leftJoin ( $class, [ $alias = ''], [ $conditions = array ()], [ $conjunction = xPDOQuery::SQL_AND], [ $binding = null], [ $condGroup = 0])
  • $class
  • $alias
  • $conditions
  • $conjunction
  • $binding
  • $condGroup
limit (line 333)

Add a LIMIT/OFFSET clause to the query.

  • return: Returns the instance.
  • access: public
xPDOQuery limit (integer $limit, [integer $offset = 0])
  • integer $limit: The number of records to return.
  • integer $offset: The location in the result set to start from.
orCondition (line 292)
  • access: public
void orCondition ( $conditions, [ $binding = null], [ $group = 0])
  • $conditions
  • $binding
  • $group
parseConditions (line 503)

Parses an xPDO condition expression.

  • access: public
void parseConditions (mixed $conditions, [string $conjunction = xPDOQuery::SQL_AND])
  • mixed $conditions: A valid xPDO condition expression.
  • string $conjunction: The optional conjunction for the condition( s ).

Redefined in descendants as:
prepare (line 489)

Prepares the xPDOQuery for execution.

  • return: The xPDOStatement representing the prepared query.
  • access: public
xPDOStatement prepare ([ $bindings = array ()], [ $byValue = true], [ $cacheFlag = null])
  • $bindings
  • $byValue
  • $cacheFlag

Redefinition of:
xPDOCriteria::prepare()
Prepares the sql and bindings of this instance into a PDOStatement.
rightJoin (line 235)
  • access: public
void rightJoin ( $class, [ $alias = ''], [ $conditions = array ()], [ $conjunction = xPDOQuery::SQL_AND], [ $binding = null], [ $condGroup = 0])
  • $class
  • $alias
  • $conditions
  • $conjunction
  • $binding
  • $condGroup
select (line 164)

Specify columns to return from the SQL query.

  • return: Returns the current object for convenience.
  • access: public
xPDOQuery select ([string $columns = '*'])
  • string $columns: Columns to return from the query.
setClassAlias (line 153)

Sets a SQL alias for the table represented by the main class.

  • return: Returns the current object for convenience.
  • access: public
xPDOQuery setClassAlias ([string $alias = ''])
  • string $alias: An alias for the main table for the SQL statement.
sortby (line 304)

Add an ORDER BY clause to the query.

  • return: Returns the instance.
  • access: public
xPDOQuery sortby (string $column, [string $direction = 'ASC'])
  • string $column: Column identifier to sort by.
  • string $direction: The direction to sort by, ASC or DESC.
where (line 283)

Add a WHERE condition to the query.

  • return: Returns the instance.
  • access: public
xPDOQuery where ([mixed $conditions = ''], [string $conjunction = xPDOQuery::SQL_AND], [mixed $binding = null], [integer $condGroup = 0])
  • mixed $conditions: A valid xPDO criteria expression.
  • string $conjunction: The conjunction to use when appending this condition, i.e., AND or OR.
  • mixed $binding: A value or PDO binding representation of a value for the condition.
  • integer $condGroup: A numeric identifier for associating conditions into groups.
wrap (line 706)

Wrap an existing xPDOCriteria into this xPDOQuery instance.

  • access: public
void wrap (xPDOCriteria $criteria)

Inherited Methods

Inherited From xPDOCriteria

 xPDOCriteria::__construct()
 xPDOCriteria::bind()
 xPDOCriteria::equals()
 xPDOCriteria::prepare()
 xPDOCriteria::toSQL()
Class Constants
SQL_AND = 'AND' (line 36)
SQL_JOIN_CROSS = 'JOIN' (line 38)
SQL_JOIN_LEFT = 'LEFT JOIN' (line 39)
SQL_JOIN_NATURAL_LEFT = 'NATURAL LEFT JOIN' (line 41)
SQL_JOIN_NATURAL_RIGHT = 'NATURAL RIGHT JOIN' (line 42)
SQL_JOIN_RIGHT = 'RIGHT JOIN' (line 40)
SQL_JOIN_STRAIGHT = 'STRAIGHT_JOIN' (line 43)
SQL_OR = 'OR' (line 37)

Documentation generated on Mon, 27 Dec 2010 11:08:32 -0700 by phpDocumentor 1.4.3