public function exec() { if (!$this->querySqlToExec && !$this->hasSelect) { $this->select('*'); } parent::exec(); }
public function exec() { if (!$this->querySqlToExec) { $this->finalizeQuery(); } if (empty($this->unionArray)) { if (__Config::get('ACL_ROLES')) { $application = org_glizy_ObjectValues::get('org.glizy', 'application'); $user = $application->getCurrentUser(); if ($user->id && !$user->acl($application->getPageId(), 'all')) { $this->addAcl(); } } try { parent::exec(); } catch (Exception $e) { require_once org_glizy_Paths::get('CORE_LIBS') . 'sql-formatter/lib/SqlFormatter.php'; $trace = $e->getTrace(); var_dump($trace[0]['args'][0]->errorInfo); echo SqlFormatter::format($sql) . '</br></br>'; var_dump($this->unionArrayParams); } } else { $this->unionArray[] = $this->qb; $this->unionArrayParams = array_merge($this->unionArrayParams, $this->qb->getParameters()); if (!empty($this->unionOrderBy)) { list($fieldName, $order) = $this->unionOrderBy; if (!$this->ar->getField($fieldName)->isSystemField) { $indexType = $this->ar->getIndexFieldType($fieldName); $documentDetailIdName = $this->ar->getDocumentDetailTableIdName(); $documentTableIndexPrefix = $this->ar->getDocumentIndexTablePrefix(); $indexAlias = 'orderIndex'; $indexTablePrefix = $documentTableIndexPrefix . $indexType; $documentFieldIndexPrefix = $this->ar->getDocumentIndexFieldPrefix(); $indexFieldPrefix = $documentFieldIndexPrefix . $indexType; $indexFieldPrefixAlias = $indexAlias . '.' . $indexFieldPrefix; $detailAlias = $this->options['type'] == 'PUBLISHED_DRAFT' ? self::DOCUMENT_DETAIL_TABLE_PUBLISHED_ALIAS : self::DOCUMENT_DETAIL_TABLE_ALIAS; foreach ($this->unionArray as $qb) { $qb->addSelect('orderIndex.*'); $qb->join(self::DOCUMENT_TABLE_ALIAS, $indexTablePrefix . '_tbl', 'orderIndex', $this->expr->eq($detailAlias . '.' . $documentDetailIdName, $indexFieldPrefixAlias . '_FK_document_detail_id')); $qb->andWhere($this->expr->eq("{$indexFieldPrefixAlias}_name", ':orderIndex')); } $this->unionArrayParams[":orderIndex"] = $fieldName; $orderSql = "ORDER BY {$indexFieldPrefix}_value"; } else { $orderSql = "ORDER BY {$fieldName} {$order}"; } } $sqlArray = array(); foreach ($this->unionArray as $qb) { if (!$this->siteSet && $this->ar->getSiteField()) { $qb->andWhere($this->expr->eq($this->ar->getSiteField(), ':site')); $this->unionArrayParams[":site"] = $this->ar->getSiteid(); } $sqlArray[] = $qb->getSql(); } $sql = '(' . implode(') UNION (', $sqlArray) . ')'; if (!empty($this->unionOrderBy)) { $sql .= $orderSql; } try { if (__Config::get('QUERY_CACHING') && ($cacheDriver = org_glizy_dataAccessDoctrine_DataAccess::getCache())) { $lifeTime = __Config::get('QUERY_CACHING_LIFETIME'); $key = md5($sql); $this->statement = $this->ar->getConnection()->executeQuery($sql, $this->unionArrayParams, array(), new QueryCacheProfile($lifeTime, $key, $cacheDriver)); } else { $this->statement = $this->ar->getConnection()->executeQuery($sql, $this->unionArrayParams); } } catch (Exception $e) { require_once org_glizy_Paths::get('CORE_LIBS') . 'sql-formatter/lib/SqlFormatter.php'; $trace = $e->getTrace(); var_dump($trace[0]['args'][0]->errorInfo); echo SqlFormatter::format($sql) . '</br></br>'; var_dump($this->unionArrayParams); } $this->resetQuery(); } }