PHP Class SQLSelectClause

显示文件 Open project: sourcefabric/newscoop Class Usage Examples

Public Methods

Method Description
__construct ( $p_indent ) Class constructor
addColumn ( string $p_column ) : void Adds a column to be fetched by the query.
addConditionalWhere ( string $p_condition ) : void Adds a conditional WHERE condition to the query (using 'OR' operator)
addGroupField ( $p_field ) Add group field
addHaving ( $p_condition ) Add HAVING condition
addJoin ( string $p_join ) : void Adds a table join to the query.
addOrderBy ( string $p_order ) : void Adds an ORDER BY condition to the query.
addTableFrom ( string $p_table ) : void Adds a table to the FROM part of the query.
addWhere ( string $p_condition ) : void Adds a WHERE condition to the query.
buildQuery ( ) : string Builds the SQL query from the object attributes.
setDistinct ( string $p_column = null ) : void Sets all or specific column(s) to be fetched DISTINCT.
setLimit ( integer $p_start, integer $p_offset ) : void Sets the LIMIT of the query.
setTable ( string $p_table ) : void Sets the name of the main table in the query.

Private Methods

Method Description
buildColumns ( ) : string Builds the list of columns to be retrieved by the query.
buildFrom ( ) : string Builds the FORM part of the query based on the main table and whether there is some table to join with.
buildGroupBy ( ) : string Builds the GROUP BY clause.
buildHaving ( ) : string Builds the HAVING clause.
buildOrderBy ( ) : string Builds the ORDER BY conditions.
buildWhere ( ) : string Builds the list of WHERE conditions.
hasFrom ( ) : boolean Returns whether there is FROM tables other than the main query table.
hasJoins ( ) : boolean Returns whether there is table joins.
indent ( $p_inner ) : string Returns the indentation string

Method Details

__construct() public method

Class constructor
public __construct ( $p_indent )

addColumn() public method

Adds a column to be fetched by the query.
public addColumn ( string $p_column ) : void
$p_column string The name of the column
return void

addConditionalWhere() public method

Adds a conditional WHERE condition to the query (using 'OR' operator)
public addConditionalWhere ( string $p_condition ) : void
$p_condition string The comparison operation
return void

addGroupField() public method

Add group field
public addGroupField ( $p_field )
$p_field

addHaving() public method

Add HAVING condition
public addHaving ( $p_condition )
$p_condition

addJoin() public method

Adds a table join to the query.
public addJoin ( string $p_join ) : void
$p_join string The full join string including the ON condition
return void

addOrderBy() public method

Adds an ORDER BY condition to the query.
public addOrderBy ( string $p_order ) : void
$p_order string The column and the direction of the order condition
return void

addTableFrom() public method

Adds a table to the FROM part of the query.
public addTableFrom ( string $p_table ) : void
$p_table string The name of the table
return void

addWhere() public method

Adds a WHERE condition to the query.
public addWhere ( string $p_condition ) : void
$p_condition string The comparison operation
return void

buildQuery() public method

Builds the SQL query from the object attributes.
public buildQuery ( ) : string
return string $sql The full SQL query

setDistinct() public method

Sets all or specific column(s) to be fetched DISTINCT.
public setDistinct ( string $p_column = null ) : void
$p_column string The column which have to fetched distinct
return void

setLimit() public method

Sets the LIMIT of the query.
public setLimit ( integer $p_start, integer $p_offset ) : void
$p_start integer The number where the query will start to fetch data
$p_offset integer The number of rows to be fetched
return void

setTable() public method

Sets the name of the main table in the query.
public setTable ( string $p_table ) : void
$p_table string The name of the table
return void