Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion classes/DataWarehouse/Data/BatchDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ class BatchDataset extends Loggable implements Iterator
*/
private $offset;

/**
* The original setting of MYSQL_ATTR_USE_BUFFERED_QUERY before the query
* is run. After the last row is fetched, the setting is set back to this
* value.
*/
private $originalBufferedQuerySetting;

/**
* @param RawQuery $query
* @param XDUser $user
Expand Down Expand Up @@ -199,13 +206,16 @@ public function next()
*/
public function rewind()
{
$this->originalBufferedQuerySetting = $this->dbh->handle()->getAttribute(
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY
);
$this->dbh->handle()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$this->logger->debug('Executing query');
$this->sth = $this->query->getRawStatement($this->limit, $this->offset);
$this->logger->debug(sprintf(
'Raw query string: %s',
$this->sth->queryString
));
$this->logger->debug(sprintf('Row count: %s', $this->sth->rowCount()));
$this->currentRowIndex = 1;
$this->currentRow = $this->getNextRow();
}
Expand Down Expand Up @@ -248,6 +258,10 @@ private function getNextRow()
$rawRow = $this->sth->fetch(PDO::FETCH_ASSOC);

if ($rawRow === false) {
$this->dbh->handle()->setAttribute(
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,
$this->originalBufferedQuerySetting
);
return false;
}

Expand Down
3 changes: 0 additions & 3 deletions classes/Rest/Controllers/WarehouseControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2368,9 +2368,7 @@ private static function echoRawData(
$query,
$logger
);
$pdo = DB::factory($query->_db_profile)->handle();
if ($isFirstQueryInSeries) {
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
self::echoRawDataRow($dataset->getHeader());
}
foreach ($dataset as $row) {
Expand All @@ -2390,7 +2388,6 @@ private static function echoRawData(
}
if ($isLastQueryInSeries) {
echo "0\r\n\r\n";
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}
}

Expand Down