Fixes to pdo reader and stream

This commit is contained in:
2024-03-15 14:28:55 +01:00
parent 71a6a9d0ad
commit 41c57c2b9f
2 changed files with 11 additions and 11 deletions
+1 -1
View File
@@ -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);
}
}
+10 -10
View File
@@ -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();