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); }
public function totalRows() { if ($this->totalRows === null) { $this->totalRows = (int) $this->paginator->count(); } return $this->totalRows; }
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); }
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); }
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; }
/** * 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; }
/** * @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()); }
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()); }
/** * @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()); }