diff --git a/src/Library/Benzina/Pdo/PdoReader.php b/src/Library/Benzina/Pdo/PdoReader.php index 867858a..e8d7682 100644 --- a/src/Library/Benzina/Pdo/PdoReader.php +++ b/src/Library/Benzina/Pdo/PdoReader.php @@ -40,7 +40,7 @@ class PdoReader implements ReaderInterface $count = $this->db->query("SELECT COUNT(*) FROM `$name`;")->fetchColumn(); $query = $this->db->prepare("SELECT * FROM `$name` LIMIT ? OFFSET ?;"); - $stream = new Stream(str_repeat("\n", $count)); + $stream = new Stream(str_repeat("0", $count)); return new PdoStream($stream, $query); } } diff --git a/src/Library/Benzina/Pdo/PdoStream.php b/src/Library/Benzina/Pdo/PdoStream.php index 5d906d7..9ca441b 100644 --- a/src/Library/Benzina/Pdo/PdoStream.php +++ b/src/Library/Benzina/Pdo/PdoStream.php @@ -18,22 +18,17 @@ class PdoStream implements StreamInterface public function eof(): bool { - return $this->stream->eof(); + return $this->currentBatch > $this->length(); } public function read(?int $length = null): mixed { - while (!$this->stream->eof()) { - $this->stream->read(self::BATCH_SIZE); - $this->pdo->execute([self::BATCH_SIZE, $this->currentBatch]); + $this->stream->read(self::BATCH_SIZE); + $this->pdo->execute([self::BATCH_SIZE, $this->currentBatch]); - $result = $this->pdo->fetchAll(); - $this->currentBatch += self::BATCH_SIZE; + $this->currentBatch += self::BATCH_SIZE; - return $result; - } - - $this->stream->close(); + return $this->pdo->fetchAll(); } public function close(): void @@ -41,6 +36,11 @@ class PdoStream implements StreamInterface $this->stream->close(); } + public function tell(): int + { + return $this->currentBatch; + } + public function length(): int { return $this->stream->length();