Skip to content

Commit 5ff56a7

Browse files
committed
- Fixed return of RunnableSelect::fetch when in object-mode
1 parent b328433 commit 5ff56a7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Builder/RunnableSelect.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public function fetchRowsLazy(Closure $callback = null) {
8080
* @throws \Exception
8181
*/
8282
public function fetchRow(Closure $callback = null) {
83-
return $this->fetch($callback, PDO::FETCH_ASSOC);
83+
return $this->fetch($callback, PDO::FETCH_ASSOC, null, function ($row) {
84+
return ['valid' => is_array($row), 'default' => []];
85+
});
8486
}
8587

8688
/**
@@ -109,7 +111,9 @@ public function fetchObjectsLazy($className, Closure $callback = null) {
109111
* @throws \Exception
110112
*/
111113
public function fetchObject($className, Closure $callback = null) {
112-
return $this->fetch($callback, PDO::FETCH_CLASS, $className);
114+
return $this->fetch($callback, PDO::FETCH_CLASS, $className, function ($row) {
115+
return ['valid' => is_object($row), 'default' => null];
116+
});
113117
}
114118

115119
/**
@@ -279,15 +283,17 @@ private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) {
279283
* @param Closure $callback
280284
* @param int $mode
281285
* @param mixed $arg0
286+
* @param Closure $resultValidator
282287
* @return mixed
283288
* @throws \Exception
284289
*/
285-
private function fetch(Closure $callback = null, $mode, $arg0 = null) {
286-
return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) {
290+
private function fetch(Closure $callback = null, $mode, $arg0 = null, Closure $resultValidator = null) {
291+
return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) {
287292
$statement->setFetchMode($mode, $arg0);
288293
$row = $statement->fetch();
289-
if(!is_array($row)) {
290-
return [];
294+
$result = $resultValidator($row);
295+
if(!$result['valid']) {
296+
return $result['default'];
291297
}
292298
if($this->preserveTypes) {
293299
$columnDefinitions = FieldTypeProvider::getFieldTypes($statement);

0 commit comments

Comments
 (0)