Ejemplo n.º 1
0
 /**
  * Processa a query de consulta
  * @param Expression $qry
  * @return array No formato queryresult
  */
 protected function proccessQuery(Expression $qry)
 {
     $params = array();
     $sql = '';
     if ($qry->hasWhere()) {
         $sql = $qry->getWhere()->getSQL() . ' ';
         $params = $qry->getWhere()->getParams();
     }
     if ($qry->hasGroupBy()) {
         $sql .= 'GROUP BY ' . implode(',', $qry->getGroupBy()) . ' ';
     }
     if ($qry->hasHaving()) {
         $count = 1;
         $sql .= str_replace('WHERE', 'HAVING', $qry->getHaving()->getSQL(), $count) . ' ';
         $params = array_merge($params, $qry->getHaving()->getParams());
     }
     if ($qry->hasOrderBy()) {
         $order = array();
         foreach ($qry->getOrderBy() as $cp => $ord) {
             $order[] = $cp . ' ' . $ord;
         }
         $sql .= 'ORDER BY ' . implode(',', $order) . ' ';
     }
     if ($qry->hasLimit()) {
         $sql .= 'LIMIT ? ';
         $params[] = $qry->getLimit();
     }
     if ($qry->hasOffset() && $qry->getOffset() > 0) {
         $sql .= 'OFFSET ? ';
         $params[] = $qry->getOffset();
     }
     return $this->getQueryResult($sql, $params);
 }
Ejemplo n.º 2
0
 /**
  * @covers Expression::setHaving
  * @covers Expression::getHaving
  * @covers Expression::hasHaving
  * @covers Expression::clearHaving
  */
 public function testHaving()
 {
     $this->assertFalse($this->object->hasHaving(), 'Having deveria ser vazio');
     $this->assertEquals($this->object, $this->object->setHaving(array('id' => 1)), 'Não retornou o objeto');
     $this->assertTrue($this->object->hasHaving(), 'Having não deveria ser vazio');
     $this->assertEquals(array(1), $this->object->getHaving()->getParams(), 'Parametro inválido para o having');
     $this->object->setHaving(array());
     $this->assertFalse($this->object->hasHaving(), 'Having deveria ser vazio novamente');
     $where = Where::getInstance(array('id' => 2));
     $this->object->setHaving($where);
     $this->assertEquals($where, $this->object->getHaving());
     $this->assertEquals($this->object, $this->object->clearHaving(), 'Não retornou o objeto');
     $this->assertFalse($this->object->hasHaving(), 'Having deveria ser vazio novamente');
 }