From aa9eb2f82f31f5aa4e5ce1b786e5599448b5048c Mon Sep 17 00:00:00 2001 From: Marcus Brasizza Date: Wed, 23 Apr 2025 10:34:54 -0300 Subject: [PATCH] Update SelectQuery.php add fetch() to return just one value when you know that your sql will return just one line that you don't need to check and make transformations --- src/Query/SelectQuery.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Query/SelectQuery.php b/src/Query/SelectQuery.php index 52a39271..0fec98f1 100644 --- a/src/Query/SelectQuery.php +++ b/src/Query/SelectQuery.php @@ -368,7 +368,18 @@ public function getIterator(): StatementInterface { return $this->run(); } - + /** + * Request the first result as array (when you know that you have just one result). + */ + public function fetch(int $mode = StatementInterface::FETCH_ASSOC): array + { + $st = $this->run(); + try { + return $st->fetch($mode); + } finally { + $st->close(); + } + } /** * Request all results as array. */