예제 #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);
 }
예제 #2
0
 /**
  * @covers Expression::setWhere
  * @covers Expression::getWhere
  * @covers Expression::hasWhere
  * @covers Expression::clearWhere
  */
 public function testWhere()
 {
     $this->assertFalse($this->object->hasWhere(), 'Where deveria ser vazio');
     $this->assertEquals($this->object, $this->object->setWhere(array('id' => 1)), 'Não retornou o objeto');
     $this->assertTrue($this->object->hasWhere(), 'Where não deveria ser vazio');
     $this->assertEquals(array(1), $this->object->getWhere()->getParams(), 'Parametro inválido para o where');
     $this->object->setWhere(array());
     $this->assertFalse($this->object->hasWhere(), 'Where deveria ser vazio novamente');
     $where = Where::getInstance(array('id' => 2));
     $this->object->setWhere($where);
     $this->assertEquals($where, $this->object->getWhere());
     $this->assertEquals($this->object, $this->object->clearWhere(), 'Não retornou o objeto');
     $this->assertFalse($this->object->hasWhere(), 'Where deveria ser vazio novamente');
 }