Permalink
Browse files

Fixed fetchIterator, so that it uses cursor properly.

  • Loading branch information...
bbankowski committed Nov 6, 2017
1 parent 86b9d68 commit a5501dfcd099938207f8f0289fd632f3d56611a0
View
@@ -6,6 +6,7 @@ INCOMING
Enhancements:
* [ORM] Model implements Serializable and JsonSerializable interfaces (issue #203).
* [ORM] Changed Model::deleteEach to use iterator instead of fetching all elements at once (issue #254).
* [ORM] Fixed fetchIterator to properly use cursor underneath.
* [DI] Added constructor injection for arguments with types defined (issue #265).
* [Utilities] Added equalsIgnoreCase to Functions and FluentFunctions (issue #263).
* [Utilities] Fixed Clock to support DST changes when adding hours, minutes or seconds.
@@ -10,7 +10,7 @@ class EmulatedPDOPreparedStatementExecutor extends PDOExecutor
/**
* @inheritdoc
*/
public function createPDOStatement($dbHandle, $sql, $boundValues, $queryString)
public function createPDOStatement($dbHandle, $sql, $boundValues, $queryString, $options = [])
{
$sql = PreparedStatementEmulator::substitute($sql, $boundValues);
@@ -16,9 +16,10 @@
* @param string $sql
* @param array $boundValues
* @param string $queryString
* @param array $options
* @return PDOStatement
*/
abstract public function createPDOStatement($dbHandle, $sql, $boundValues, $queryString);
abstract public function createPDOStatement($dbHandle, $sql, $boundValues, $queryString, $options = []);
/**
* @param array $options
@@ -12,9 +12,9 @@ class PDOPreparedStatementExecutor extends PDOExecutor
/**
* @inheritdoc
*/
public function createPDOStatement($dbHandle, $sql, $boundValues, $queryString)
public function createPDOStatement($dbHandle, $sql, $boundValues, $queryString, $options = [])
{
$pdoStatement = $dbHandle->prepare($sql);
$pdoStatement = $dbHandle->prepare($sql, $options);
if (!$pdoStatement) {
throw PDOExceptionExtractor::getException($dbHandle->errorInfo(), $queryString);
@@ -121,19 +121,20 @@ public static function prepare($dbHandle, $sql, $boundValues, $options)
public function fetchIterator()
{
return Stats::trace($this->humanizedSql, $this->boundValues, function () {
$pdoStatement = $this->_createPdoStatement();
$pdoStatement = $this->_createPdoStatement([PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL]);
return new StatementIterator($pdoStatement);
});
}
/**
* @param array $options
* @return PDOStatement
*/
public function _createPdoStatement()
public function _createPdoStatement($options = [])
{
$sqlString = $this->humanizedSql . ' with params: ' . Objects::toString($this->boundValues);
Logger::getLogger(__CLASS__)->info("Query: %s", [$sqlString]);
return $this->pdoExecutor->createPDOStatement($this->dbHandle, $this->sql, $this->boundValues, $sqlString);
return $this->pdoExecutor->createPDOStatement($this->dbHandle, $this->sql, $this->boundValues, $sqlString, $options);
}
}

0 comments on commit a5501df

Please sign in to comment.