diff --git a/VERSION b/VERSION index b6c00dc..c16f6bf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2311.91351 +0.2311.91403 diff --git a/src/Data/DbResultTrait.php b/src/Data/DbResultTrait.php index faa2dd5..1e18d87 100644 --- a/src/Data/DbResultTrait.php +++ b/src/Data/DbResultTrait.php @@ -29,4 +29,12 @@ trait DbResultTrait { public function getFloatOrNull(int|string $index): ?float { return $this->isNull($index) ? null : (float)$this->getValue($index); } + + public function getBoolean(int|string $index): bool { + return $this->getInteger($index) !== 0; + } + + public function getBooleanOrNull(int|string $index): ?bool { + return $this->isNull($index) ? null : ($this->getInteger($index) !== 0); + } } diff --git a/src/Data/IDbResult.php b/src/Data/IDbResult.php index 2a6dcf2..5dcac9e 100644 --- a/src/Data/IDbResult.php +++ b/src/Data/IDbResult.php @@ -83,6 +83,22 @@ interface IDbResult extends ICloseable { */ function getFloatOrNull(int|string $index): ?float; + /** + * Gets the value from the target index cast as a boolean value. + * + * @param int|string $index Target index. + * @return bool Returns the value cast to a boolean value. + */ + function getBoolean(int|string $index): bool; + + /** + * Checks if the field is null, then gets the value from the target index cast as a boolean value. + * + * @param int|string $index Target index. + * @return ?bool Returns the value cast to a boolean value or null. + */ + function getBooleanOrNull(int|string $index): ?bool; + /** * Gets the value from the target index as a Stream. * diff --git a/src/Data/NullDb/NullDbResult.php b/src/Data/NullDb/NullDbResult.php index fa36cd1..961ea27 100644 --- a/src/Data/NullDb/NullDbResult.php +++ b/src/Data/NullDb/NullDbResult.php @@ -48,6 +48,14 @@ class NullDbResult implements IDbResult { return null; } + public function getBoolean(int|string $index): bool { + return false; + } + + public function getBooleanOrNull(int|string $index): ?bool { + return null; + } + public function getStream(int|string $index): ?Stream { return null; }