src/DB/StatementBuilder.php
public function buildSelectStatement()
	{
		if( !$this->keys )
			throw new RuntimeException( 'No Columns defined.' );
		if( !$this->tables )
			throw new RuntimeException( 'No Tables defined.' );

		$tables		= array();
		$keys		= "SELECT\n\t".implode( ",\n\t", $this->keys );
		$tables		= "\nFROM\n\t".implode( ",\n\t", $this->tables );
		$conditions	= "";
		$groupings	= "";
		$havings	= "";
		$limit		= "";

		if( $this->conditions )
			$conditions	= "\nWHERE\n\t".implode( " AND\n\t", $this->conditions );
		if( $this->groupings )
			$groupings	= "\nGROUP BY\n\t".implode( ",\n\t", $this->groupings );
		if( $this->havings )
			$havings	= "\nHAVING\n\t".implode( ",\n\t", $this->havings );
		$orders		= "";
		if( count( $this->orders ) )
		{
			$orders	= array();
			foreach( $this->orders as $column => $direction )
				$orders[] = $column." ".$direction;
			$orders		= "\nORDER BY\n\t".implode( ",\n\t", $orders );
		}
		if( $this->limit )
		{
			$limit = "\nLIMIT ".$this->limit;
			if( $this->offset )
				$limit .= "\nOFFSET ".$this->offset;
		}
		$statement = $keys.$tables.$conditions.$groupings.$havings.$orders.$limit;
		return $statement;
	}
public function buildSelectStatement()
	{
		if( !$this->keys )
			throw new RuntimeException( 'No Columns defined.' );
		if( !$this->tables )
			throw new RuntimeException( 'No Tables defined.' );

		$tables		= array();
		$keys		= "SELECT\n\t".implode( ",\n\t", $this->keys );
		$tables		= "\nFROM\n\t".implode( ",\n\t", $this->tables );
		$conditions	= "";
		$groupings	= "";
		$havings	= "";
		$limit		= "";

		if( $this->conditions )
			$conditions	= "\nWHERE\n\t".implode( " AND\n\t", $this->conditions );
		if( $this->groupings )
			$groupings	= "\nGROUP BY\n\t".implode( ",\n\t", $this->groupings );
		if( $this->havings )
			$havings	= "\nHAVING\n\t".implode( ",\n\t", $this->havings );
		$orders		= "";
		if( count( $this->orders ) )
		{
			$orders	= array();
			foreach( $this->orders as $column => $direction )
				$orders[] = $column." ".$direction;
			$orders		= "\nORDER BY\n\t".implode( ",\n\t", $orders );
		}
		if( $this->limit )
		{
			$limit = "\nLIMIT ".$this->limit;
			if( $this->offset )
				$limit .= "\nOFFSET ".$this->offset;
		}
		$statement = $keys.$tables.$conditions.$groupings.$havings.$orders.$limit;
		return $statement;
	}
public function buildSelectStatement ( ) { if ( ! $ this -> keys ) throw new RuntimeException ( 'No Columns defined.' ) ; if ( ! $ this -> tables ) throw new RuntimeException ( 'No Tables defined.' ) ; $ tables = array ( ) ; $ keys = "SELECT\n\t" . implode ( ",\n\t" , $ this -> keys ) ; $ tables = "\nFROM\n\t" . implode ( ",\n\t" , $ this -> tables ) ; $ conditions = "" ; $ groupings = "" ; $ havings = "" ; $ limit = "" ; if ( $ this -> conditions ) $ conditions = "\nWHERE\n\t" . implode ( " AND\n\t" , $ this -> conditions ) ; if ( $ this -> groupings ) $ groupings = "\nGROUP BY\n\t" . implode ( ",\n\t" , $ this -> groupings ) ; if ( $ this -> havings ) $ havings = "\nHAVING\n\t" . implode ( ",\n\t" , $ this -> havings ) ; $ orders = "" ; if ( count ( $ this -> orders ) ) { $ orders = array ( ) ; foreach ( $ this -> orders as $ column => $ direction ) $ orders [ ] = $ column . " " . $ direction ; $ orders = "\nORDER BY\n\t" . implode ( ",\n\t" , $ orders ) ; } if ( $ this -> limit ) { $ limit = "\nLIMIT " . $ this -> limit ; if ( $ this -> offset ) $ limit .= "\nOFFSET " . $ this -> offset ; } $ statement = $ keys . $ tables . $ conditions . $ groupings . $ havings . $ orders . $ limit ; return $ statement ; }
Builds SQL Statement.
@access		public
@return		string
Builds SQL Statement .