示例#1
0
 public function testCount()
 {
     $this->mockSelect->expects($this->once())->method('columns')->with($this->equalTo(array('c' => new Expression('COUNT(1)'))));
     $this->mockResult->expects($this->any())->method('current')->will($this->returnValue(array('c' => 5)));
     $count = $this->dbSelect->count();
     $this->assertEquals(5, $count);
 }
示例#2
0
 public function totalRows()
 {
     if ($this->totalRows === null) {
         $this->totalRows = (int) $this->paginator->count();
     }
     return $this->totalRows;
 }
示例#3
0
 public function testCount()
 {
     $this->mockResult->expects($this->once())->method('current')->will($this->returnValue(array('c' => 5)));
     $this->mockSelect->expects($this->exactly(3))->method('reset');
     // called for columns, limit, offset, order
     $count = $this->dbSelect->count();
     $this->assertEquals(5, $count);
 }
示例#4
0
 public function testCount()
 {
     $this->mockSelect->expects($this->once())->method('columns')->with($this->equalTo(array('c' => new Expression('COUNT(1)'))));
     $this->mockResult->expects($this->any())->method('current')->will($this->returnValue(array('c' => 5)));
     $this->mockSelect->expects($this->exactly(6))->method('reset');
     // called for columns, limit, offset, order
     $this->mockSelect->expects($this->once())->method('getRawState')->with($this->equalTo(Select::JOINS))->will($this->returnValue(array(array('name' => 'Foo', 'on' => 'On Stuff', 'columns' => array('foo', 'bar'), 'type' => Select::JOIN_INNER))));
     $this->mockSelect->expects($this->once())->method('join')->with('Foo', 'On Stuff', array(), Select::JOIN_INNER);
     $count = $this->dbSelect->count();
     $this->assertEquals(5, $count);
 }
示例#5
0
 public function getLogNum()
 {
     $bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
     $select = new Select();
     $select->from($bsqlch->strdbcompat("Log"));
     $resultSetPrototype = new ResultSet();
     $resultSetPrototype->setArrayObjectPrototype(new Log());
     $rowset = new DbSelect($select, $this->tableGateway->getAdapter(), $resultSetPrototype);
     $num = $rowset->count();
     return $num;
 }
示例#6
0
 public function getItems($a, $b)
 {
     $items = parent::getItems($a, $b);
     $return = array();
     foreach ($items as $item) {
         $return[] = $item;
     }
     return $return;
 }
示例#7
0
 /**
  * Constructs instance.
  *
  * @param TableGateway                $tableGateway
  * @param Where|\Closure|string|array $where
  * @param null                        $order
  */
 public function __construct(TableGateway $tableGateway, $where = null, $order = null)
 {
     $select = $tableGateway->getSql()->select();
     if ($where) {
         $select->where($where);
     }
     if ($order) {
         $select->order($order);
     }
     $dbAdapter = $tableGateway->getAdapter();
     $resultSetPrototype = $tableGateway->getResultSetPrototype();
     parent::__construct($select, $dbAdapter, $resultSetPrototype);
 }
示例#8
0
 /**
  * Returns the total number of rows in the result set.
  *
  * @return integer
  */
 public function count()
 {
     if (null !== $this->rowCount) {
         return $this->rowCount;
     }
     $originalSelect = $this->select;
     $this->select = clone $this->select;
     $joins = $this->select->getRawState(Select::JOINS);
     $this->select->quantifier('')->reset(Select::JOINS);
     foreach ($joins as $join) {
         $this->select->join($join['name'], $join['on'], array(), $join['type']);
     }
     $result = parent::count();
     $this->select = $originalSelect;
     return $result;
 }
示例#9
0
 /**
  * Constructs instance.
  *
  * @param TableGateway                      $tableGateway
  * @param null|Where|\Closure|string|array  $where
  * @param null|string|array                 $order
  * @param null|string|array                 $group
  * @param null|Having|\Closure|string|array $having
  */
 public function __construct(TableGateway $tableGateway, $where = null, $order = null, $group = null, $having = null)
 {
     $sql = $tableGateway->getSql();
     $select = $sql->select();
     if ($where) {
         $select->where($where);
     }
     if ($order) {
         $select->order($order);
     }
     if ($group) {
         $select->group($group);
     }
     if ($having) {
         $select->having($having);
     }
     $resultSetPrototype = $tableGateway->getResultSetPrototype();
     parent::__construct($select, $sql, $resultSetPrototype);
 }
示例#10
0
 /**
  * @group ZF-10704
  */
 public function testObjectSelectWithBind()
 {
     $select = $this->_db->select();
     $select->from('test', array('number'))->where('number = ?')->distinct(true)->bind(array(250));
     $adapter = new Adapter\DbSelect($select);
     $this->assertEquals(1, $adapter->count());
     $select->reset(Sql\Select::DISTINCT);
     $select2 = clone $select;
     $select2->reset(Sql\Select::WHERE)->where('number = 500');
     $selectUnion = $this->_db->select()->bind(array(250));
     $selectUnion->union(array($select, $select2));
     $adapter = new Adapter\DbSelect($selectUnion);
     $this->assertEquals(2, $adapter->count());
 }
示例#11
0
 /**
  * Paginate models.
  * Minimum $page must be 1, not 0.
  *
  * @var int|string $page
  * @var int|string $perPage
  */
 public function paginate($page, $perPage = null)
 {
     $page = (int) $page;
     if ($page < 1) {
         $page = 1;
     }
     if ($perPage === null) {
         if (!($perPage = $this->select->getRawState('limit'))) {
             throw new Exception\InvalidArgumentException("No per page passed and no limit is set");
         }
     }
     $modelClass = $this->modelClass;
     $paginator = new Paginator($this->select, $modelClass::adapter());
     $items = $paginator->getItems(($page - 1) * $perPage, $perPage);
     $collection = $this->buildCollection($items->toArray());
     $collection->setPage($page);
     $collection->setPerPage($perPage);
     $collection->setPaginator($paginator);
     return $collection;
 }
示例#12
0
    public function testGroupByQueryOnEmptyTableReturnsRowCountZero()
    {
        $query = $this->_db->select()
                           ->from('test_empty')
                           ->order('number ASC')
                           ->limit(1000, 0);
        $adapter = new Adapter\DbSelect($query);

        $this->assertEquals(0, $adapter->count());
    }
示例#13
0
 /**
  * @group ZF-7127
  */
 public function testMultipleGroupSelect()
 {
     $select = $this->_db->select()->from('test')->group('testgroup')->group('number')->where('number > 250');
     $adapter = new Adapter\DbSelect($select);
     $expected = 'SELECT COUNT(1) AS "zend_paginator_row_count" FROM (SELECT "test".* FROM "test" WHERE (number > 250) GROUP BY "testgroup"' . ",\n\t" . '"number") AS "t"';
     $this->assertEquals($expected, $adapter->getCountSelect()->__toString());
     $this->assertEquals(250, $adapter->count());
 }
示例#14
0
 /**
  * Paginate models.
  * Minimum $page must be 1, not 0.
  *
  * @var int|string $page
  * @var int|string $perPage
  * @return array
  */
 public function paginate($page, $perPage = null)
 {
     if ($page < 1) {
         $page = 1;
     }
     $paginator = new Paginator($this->select, $this->adapter());
     $items = $paginator->getItems(($page - 1) * $perPage, $perPage);
     return $items->toArray();
 }