-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
618c9ed
commit d48e531
Showing
4 changed files
with
37 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,12 +343,12 @@ public function select($query, $bindings = [], $useReadPdo = true) | |
} | ||
|
||
/** | ||
* Run a select statement against the database and returns a cursor. | ||
* Run a select statement against the database and returns a generator. | ||
* | ||
* @param string $query | ||
* @param array $bindings | ||
* @param bool $useReadPdo | ||
* @return mixed | ||
* @return \Generator | ||
*/ | ||
public function cursor($query, $bindings = [], $useReadPdo = true) | ||
{ | ||
|
@@ -357,16 +357,19 @@ public function cursor($query, $bindings = [], $useReadPdo = true) | |
return []; | ||
} | ||
|
||
// For select statements, we'll simply execute the query and return an array | ||
// of the database result set. Each element in the array will be a single | ||
// row from the database table, and will either be an array or objects. | ||
$statement = $this->getPdoForSelect($useReadPdo)->prepare($query); | ||
|
||
$statement->setFetchMode($me->getFetchMode()); | ||
if ($me->getFetchMode() === PDO::FETCH_CLASS) { | ||
$statement->setFetchMode($me->getFetchMode(), 'StdClass'); | ||
} else { | ||
$statement->setFetchMode($me->getFetchMode()); | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vlakoff
Contributor
|
||
$statement->execute($me->prepareBindings($bindings)); | ||
|
||
return $statement; | ||
while ($record = $statement->fetch()) { | ||
yield $record; | ||
} | ||
}); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What if the user specified
PDO::FETCH_CLASS
and a class name ($fetchArgument
)?Maybe the code in
select()
method above could be of inspiration.