It's the connection which provides a cursor, not the query

This commit is contained in:
Johannes Meyer 2015-05-18 16:01:58 +02:00
parent 742dfcaf41
commit 0e0341f78a
6 changed files with 39 additions and 18 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Data\DataArray; namespace Icinga\Data\DataArray;
use ArrayIterator;
use Icinga\Data\Selectable; use Icinga\Data\Selectable;
use Icinga\Data\SimpleQuery; use Icinga\Data\SimpleQuery;
@ -82,6 +83,18 @@ class ArrayDatasource implements Selectable
return new SimpleQuery($this); return new SimpleQuery($this);
} }
/**
* Fetch and return all rows of the given query's result set using an iterator
*
* @param SimpleQuery $query
*
* @return ArrayIterator
*/
public function query(SimpleQuery $query)
{
return new ArrayIterator($this->fetchAll($query));
}
/** /**
* Fetch and return a column of all rows of the result set as an array * Fetch and return a column of all rows of the result set as an array
* *

View File

@ -4,6 +4,7 @@
namespace Icinga\Data\Db; namespace Icinga\Data\Db;
use PDO; use PDO;
use Iterator;
use Zend_Db; use Zend_Db;
use Icinga\Application\Benchmark; use Icinga\Application\Benchmark;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
@ -87,6 +88,18 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible
return new DbQuery($this); return new DbQuery($this);
} }
/**
* Fetch and return all rows of the given query's result set using an iterator
*
* @param DbQuery $query
*
* @return Iterator
*/
public function query(DbQuery $query)
{
return $query->getSelectQuery()->query();
}
/** /**
* Getter for database type * Getter for database type
* *

View File

@ -3,7 +3,6 @@
namespace Icinga\Data; namespace Icinga\Data;
use ArrayIterator;
use IteratorAggregate; use IteratorAggregate;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
@ -103,11 +102,11 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate
/** /**
* Return a iterable for this query's result * Return a iterable for this query's result
* *
* @return ArrayIterator * @return Iterator
*/ */
public function getIterator() public function getIterator()
{ {
return new ArrayIterator($this->fetchAll()); return $this->ds->query($this);
} }
/** /**

View File

@ -3,6 +3,7 @@
namespace Icinga\Protocol\Ldap; namespace Icinga\Protocol\Ldap;
use ArrayIterator;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Application\Logger; use Icinga\Application\Logger;
use Icinga\Application\Platform; use Icinga\Application\Platform;
@ -133,6 +134,11 @@ class Connection implements Selectable
return new Query($this); return new Query($this);
} }
public function query(Query $query)
{
return new ArrayIterator($this->fetchAll($query));
}
public function fetchOne($query, $fields = array()) public function fetchOne($query, $fields = array())
{ {
$row = (array) $this->fetchRow($query, $fields); $row = (array) $this->fetchRow($query, $fields);

View File

@ -372,16 +372,6 @@ class RepositoryQuery implements QueryInterface, Iterator
return $this->query->getOffset(); return $this->query->getOffset();
} }
/**
* Fetch and return all rows of the result set using an iterator
*
* @return Iterator
*/
public function fetch()
{
return $this;
}
/** /**
* Fetch and return the first column of this query's first row * Fetch and return the first column of this query's first row
* *
@ -533,7 +523,7 @@ class RepositoryQuery implements QueryInterface, Iterator
$this->order(); $this->order();
} }
$iterator = $this->query->fetch(); $iterator = $this->repository->getDataSource()->query($this->query);
if ($iterator instanceof IteratorAggregate) { if ($iterator instanceof IteratorAggregate) {
$this->iterator = $iterator->getIterator(); $this->iterator = $iterator->getIterator();
} else { } else {

View File

@ -3,7 +3,6 @@
namespace Icinga\Module\Monitoring\DataView; namespace Icinga\Module\Monitoring\DataView;
use ArrayIterator;
use IteratorAggregate; use IteratorAggregate;
use Icinga\Data\QueryInterface; use Icinga\Data\QueryInterface;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
@ -13,6 +12,7 @@ use Icinga\Data\ConnectionInterface;
use Icinga\Exception\QueryException; use Icinga\Exception\QueryException;
use Icinga\Web\Request; use Icinga\Web\Request;
use Icinga\Web\Url; use Icinga\Web\Url;
use Icinga\Module\Monitoring\Backend\Ido\Query\IdoQuery;
use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Module\Monitoring\Backend\MonitoringBackend;
/** /**
@ -23,7 +23,7 @@ abstract class DataView implements QueryInterface, IteratorAggregate
/** /**
* The query used to populate the view * The query used to populate the view
* *
* @var QueryInterface * @var IdoQuery
*/ */
protected $query; protected $query;
@ -61,11 +61,11 @@ abstract class DataView implements QueryInterface, IteratorAggregate
/** /**
* Return a iterator for all rows of the result set * Return a iterator for all rows of the result set
* *
* @return ArrayIterator * @return IdoQuery
*/ */
public function getIterator() public function getIterator()
{ {
return new ArrayIterator($this->fetchAll()); return $this->getQuery();
} }
/** /**