Beispiel #1
0
 /**
  * @covers Zend\Db\Sql\Expression::setTypes
  */
 public function testSetTypes()
 {
     $expression = new Expression();
     $return = $expression->setTypes(array(Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE, Expression::TYPE_LITERAL));
     $this->assertSame($expression, $return);
     return $expression;
 }
Beispiel #2
0
 /**
  * Count sql rows
  * @param $matches
  * @param $distinct
  * @return int
  */
 private function _getCount($matches = null, $distinct = false)
 {
     //initialize table gateways of not initialized
     if (!$this->isInitialized) {
         $this->initialize();
     }
     //build count expression
     $expression = new Expression();
     $expression->setExpression("COUNT(" . ($distinct ? ' DISTINCT ' : '') . "?)");
     if (empty($matches)) {
         $expression->setParameters('*');
         $expression->setTypes(array(Expression::TYPE_LITERAL));
     } else {
         $field = $this->__normalizeKeys($matches['fields']);
         $expression->setParameters($field);
         $expression->setTypes(array(Expression::TYPE_IDENTIFIER));
     }
     $select = $this->sql->select();
     //set columns to just the count expression
     $select->columns(array('count' => $expression), false);
     $statement = $this->sql->prepareStatementForSqlObject($select);
     //execute the statement and return the result
     $result = $statement->execute()->current();
     return $result['count'];
 }