public executeQuery ( string $query, array $params = [], array $types = [], Doctrine\DBAL\Cache\QueryCacheProfile $qcp = null ) : Doctrine\DBAL\Driver\Statement | ||
$query | string | The SQL query to execute. |
$params | array | The parameters to bind to the query, if any. |
$types | array | The types the previous parameters are in. |
$qcp | Doctrine\DBAL\Cache\QueryCacheProfile | The query cache profile, optional. |
return | Doctrine\DBAL\Driver\Statement | The executed statement. |
public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null)
{
if ($qcp !== null) {
return $this->executeCacheQuery($query, $params, $types, $qcp);
}
$this->connect();
$logger = $this->_config->getSQLLogger();
if ($logger) {
$logger->startQuery($query, $params, $types);
}
try {
if ($params) {
list($query, $params, $types) = SQLParserUtils::expandListParameters($query, $params, $types);
$stmt = $this->_conn->prepare($query);
if ($types) {
$this->_bindTypedValues($stmt, $params, $types);
$stmt->execute();
} else {
$stmt->execute($params);
}
} else {
$stmt = $this->_conn->query($query);
}
} catch (Exception $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types));
}
$stmt->setFetchMode($this->defaultFetchMode);
if ($logger) {
$logger->stopQuery();
}
return $stmt;
}
public function exportData($export, $reporter) { $this->conn->beginTransaction(); try { $lastExportedAt = (int) $export['lastExportedAt']; $areas = $this->conn->fetchAll('SELECT a.`id`, a.`name`, t.`id` AS `territoryId`, t.`name` AS `territoryName`, a.`customData`, a.`lastUpdatedAt` ' . 'FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = a.`territoryId` ' . 'WHERE a.`projectId` = :projectId AND a.`statusId` = :statusId', [':projectId' => $export['projectId'], ':statusId' => $export['areaStatusId']]); $block = new ExportBlock(); foreach ($areas as $area) { $block->addId($area['id']); if ($area['lastUpdatedAt'] > $lastExportedAt) { $area['customData'] = json_decode($area['customData']); $block->addUpdatedId($area['id']); $block->addUpdate($area); } } $event = new ExportEvent($export['projectId'], $export['lastExportedAt'], $reporter); $event->addBlock('area', $block); $event = $this->eventDispatcher->dispatch(ExportEvents::EXPORT_ONGOING, $event); $this->conn->executeQuery('UPDATE `' . ExportTables::DATA_EXPORT_TBL . '` SET `lastExportedAt` = :time WHERE `id` = :id', [':time' => time(), ':id' => $export['id']]); $this->conn->commit(); return $event->output(); } catch (Exception $ex) { $this->conn->rollBack(); throw $ex; } }