57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
// SqliteResult.php
|
|
// Created: 2021-05-02
|
|
// Updated: 2024-10-02
|
|
|
|
namespace Index\Data\Sqlite;
|
|
|
|
use SQLite3Result;
|
|
use InvalidArgumentException;
|
|
use Index\Data\{DbResult,DbResultTrait};
|
|
|
|
/**
|
|
* Represents an SQLite result set.
|
|
*/
|
|
class SqliteResult implements DbResult {
|
|
use DbResultTrait;
|
|
|
|
/** @var array<int|string, mixed> */
|
|
private array $currentRow = [];
|
|
|
|
/**
|
|
* Creates a new instance of SqliteResult.
|
|
*
|
|
* @param SQLite3Result $result Raw underlying result class.
|
|
* @return SqliteResult A new SqliteResult instance.
|
|
*/
|
|
public function __construct(
|
|
private SQLite3Result $result
|
|
) {}
|
|
|
|
/**
|
|
* Gets the number of columns per row in the result.
|
|
*
|
|
* @return int|string Number of columns in a row.
|
|
*/
|
|
public function getFieldCount(): int|string {
|
|
return $this->result->numColumns();
|
|
}
|
|
|
|
public function next(): bool {
|
|
$result = $this->result->fetchArray(SQLITE3_BOTH);
|
|
if($result === false)
|
|
return false;
|
|
$this->currentRow = $result;
|
|
return true;
|
|
}
|
|
|
|
public function isNull(int|string $index): bool {
|
|
return array_key_exists($index, $this->currentRow) && $this->currentRow[$index] === null;
|
|
}
|
|
|
|
public function getValue(int|string $index): mixed {
|
|
return $this->currentRow[$index] ?? null;
|
|
}
|
|
|
|
public function close(): void {}
|
|
}
|