Query Class Reference

framework to construct complex queries in a safer environment. More...

Inheritance diagram for Query:
SimpleQuery

List of all members.

Public Member Functions

 __construct ()
 Construct query & initialise variables.
 setLimitAndOffset (LimitOffsetQueryComponent $component)
 Add limits and offsets to the query.
 setSelectField (SelectFieldQueryComponent $component)
 Reset and set the field to the select statement.
 addSelectField (SelectFieldQueryComponent $component)
 Add a select field.
 addJoin (JoinQueryComponent $component)
 Add a join to the component.
 addSet (SetQueryComponent $component)
 Set a field value in an update or insert statement.
 setQueryType (QueryTypeQueryComponent $component)
 Set the query type, i.e.
 setOrder (OrderQueryComponent $component)
 Attach an order component.
 addTable (TableQueryComponent $component)
 Add a table to the query.
 addWhere (WhereQueryComponent $component)
 Add a where clause to the query.
 setAccessControl (AccessControlQueryComponent $component)
 Set access control.
 __toString ()

Detailed Description

framework to construct complex queries in a safer environment.

The usage of this class depends on the type of query you are executing, but the basic idea is to construct a query out of pluggable classes.

Once constructed SQL can be generated using the toString method, this should happen automatically if you pass the Query object to get_data or similar.

To construct a query, create a new Query() object and begin populating it with the various classes that define the various aspects of the query.

Notes:

With database tables you do not have to specify your db prefix, this will be added automatically.

Here is an example of a select query which requests some data out of the entities table with an order and limit that uses a subset where and some normal where queries:

<blockquote> // Construct the query $query = new Query();

// Say which table we're interested in $query->addTable(new TableQueryComponent("entities"));

// What fields are we interested in $query->addSelectField(new SelectFieldQueryComponent("entities","*"));

// Add access control (Default access control uses default fields on entities table. // Note that it will error without something specified here! $query->setAccessControl(new AccessControlQueryComponent());

// Set a limit and offset, may be omitted. $query->setLimitAndOffset(new LimitOffsetQueryComponent(10,0));

// Specify the order, may be omitted $query->setOrder(new OrderQueryComponent("entities", "subtype", "desc"));

// Construct a where query // // This demonstrates a WhereSet which lets you have sub wheres, a // WhereStatic which lets you compare a table field against a value and a // Where which lets you compare a table/field with another table/field. $query->addWhere( new WhereSetQueryComponent( array( new WhereStaticQueryComponent("entities", "subtype","=", 1), new WhereQueryComponent("entities","subtype","=", "entities", "subtype") ) ) );

get_data($query); </blockquote>

Author:
Curverider Ltd

Definition at line 516 of file query.php.


Constructor & Destructor Documentation

Query::__construct (  ) 

Construct query & initialise variables.

Reimplemented in SimpleQuery.

Definition at line 549 of file query.php.


Member Function Documentation

Query::__toString (  ) 

Definition at line 634 of file query.php.

Query::addJoin ( JoinQueryComponent component  ) 

Add a join to the component.

Parameters:
JoinQueryComponent $component The join.

Definition at line 590 of file query.php.

Query::addSelectField ( SelectFieldQueryComponent component  ) 

Add a select field.

Parameters:
SelectFieldQueryComponent $component Add a component.

Definition at line 583 of file query.php.

Query::addSet ( SetQueryComponent component  ) 

Set a field value in an update or insert statement.

Parameters:
SetQueryComponent $component Fields to set.

Definition at line 597 of file query.php.

Query::addTable ( TableQueryComponent component  ) 

Add a table to the query.

Parameters:
TableQueryComponent $component Table to add.

Definition at line 618 of file query.php.

Query::addWhere ( WhereQueryComponent component  ) 

Add a where clause to the query.

Parameters:
WhereQueryComponent $component The where component

Definition at line 625 of file query.php.

Query::setAccessControl ( AccessControlQueryComponent component  ) 

Set access control.

Parameters:
AccessControlQueryComponent $component Access control.

Definition at line 632 of file query.php.

Query::setLimitAndOffset ( LimitOffsetQueryComponent component  ) 

Add limits and offsets to the query.

Parameters:
LimitOffsetQueryComponent $component The limit and offset.

Definition at line 565 of file query.php.

Query::setOrder ( OrderQueryComponent component  ) 

Attach an order component.

Parameters:
OrderQueryComponent $component The order component.

Definition at line 611 of file query.php.

Query::setQueryType ( QueryTypeQueryComponent component  ) 

Set the query type, i.e.

"select", "update", "insert" & "delete".

Parameters:
QueryTypeQueryComponent $component The query type.

Definition at line 604 of file query.php.

Query::setSelectField ( SelectFieldQueryComponent component  ) 

Reset and set the field to the select statement.

Parameters:
SelectFieldQueryComponent $component Table and field component.

Definition at line 572 of file query.php.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations
Generated on Sun May 19 00:01:25 2013 for Elgg by  doxygen 1.6.3