diff --git a/classes/DataWarehouse/Data/BatchDataset.php b/classes/DataWarehouse/Data/BatchDataset.php index 22cdf126e0..94bc0df45d 100644 --- a/classes/DataWarehouse/Data/BatchDataset.php +++ b/classes/DataWarehouse/Data/BatchDataset.php @@ -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 @@ -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(); } @@ -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; } diff --git a/classes/Rest/Controllers/WarehouseControllerProvider.php b/classes/Rest/Controllers/WarehouseControllerProvider.php index 17e4494777..15251230c4 100644 --- a/classes/Rest/Controllers/WarehouseControllerProvider.php +++ b/classes/Rest/Controllers/WarehouseControllerProvider.php @@ -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) { @@ -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); } }