|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?php
-
-
- namespace yii\db;
-
- use yii\base\InvalidCallException;
-
-
- class DataReader extends \yii\base\Object implements \Iterator, \Countable
- {
-
-
- private $_statement;
- private $_closed = false;
- private $_row;
- private $_index = -1;
-
-
-
-
- public function __construct(Command $command, $config = [])
- {
- $this->_statement = $command->pdoStatement;
- $this->_statement->setFetchMode(\PDO::FETCH_ASSOC);
- parent::__construct($config);
- }
-
-
-
- public function bindColumn($column, &$value, $dataType = null)
- {
- if ($dataType === null) {
- $this->_statement->bindColumn($column, $value);
- } else {
- $this->_statement->bindColumn($column, $value, $dataType);
- }
- }
-
-
-
- public function setFetchMode($mode)
- {
- $params = func_get_args();
- call_user_func_array([$this->_statement, 'setFetchMode'], $params);
- }
-
-
-
- public function read()
- {
- return $this->_statement->fetch();
- }
-
-
-
- public function readColumn($columnIndex)
- {
- return $this->_statement->fetchColumn($columnIndex);
- }
-
-
-
- public function readObject($className, $fields)
- {
- return $this->_statement->fetchObject($className, $fields);
- }
-
-
-
- public function readAll()
- {
- return $this->_statement->fetchAll();
- }
-
-
-
- public function nextResult()
- {
- if (($result = $this->_statement->nextRowset()) !== false) {
- $this->_index = -1;
- }
-
- return $result;
- }
-
-
-
- public function close()
- {
- $this->_statement->closeCursor();
- $this->_closed = true;
- }
-
-
-
- public function getIsClosed()
- {
- return $this->_closed;
- }
-
-
-
- public function getRowCount()
- {
- return $this->_statement->rowCount();
- }
-
-
-
- public function count()
- {
- return $this->getRowCount();
- }
-
-
-
- public function getColumnCount()
- {
- return $this->_statement->columnCount();
- }
-
-
-
- public function rewind()
- {
- if ($this->_index < 0) {
- $this->_row = $this->_statement->fetch();
- $this->_index = 0;
- } else {
- throw new InvalidCallException('DataReader cannot rewind. It is a forward-only reader.');
- }
- }
-
-
-
- public function key()
- {
- return $this->_index;
- }
-
-
-
- public function current()
- {
- return $this->_row;
- }
-
-
-
- public function next()
- {
- $this->_row = $this->_statement->fetch();
- $this->_index++;
- }
-
-
-
- public function valid()
- {
- return $this->_row !== false;
- }
- }
|