Fixes to pdo reader and stream
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user