Example #1
0
 protected function query($query)
 {
     // check nosql configuration
     $configuration = $this->init_entity->getConnection()->getConfiguration();
     if (isset($configuration['handlersocket']['read'])) {
         $nosqlConnectionName = $configuration['handlersocket']['read'];
         $nosqlConnection = \Bitrix\Main\Application::getInstance()->getConnectionPool()->getConnection($nosqlConnectionName);
         $isNosqlCapable = NosqlPrimarySelector::checkQuery($nosqlConnection, $this);
         if ($isNosqlCapable) {
             $nosqlResult = NosqlPrimarySelector::relayQuery($nosqlConnection, $this);
             return new \Bitrix\Main\DB\ArrayResult($nosqlResult, $nosqlConnection);
         }
     }
     /*
     Vadim: this is for paging but currently is not used
     		if ($this->count_total || !is_null($this->offset))
     		{
     			$cnt_body_elements = $build_parts;
     
     			// remove order
     			unset($cnt_body_elements['ORDER BY']);
     
     			$cnt_query = join("\n", $cnt_body_elements);
     
     			// remove long aliases
     			list($cnt_query, ) = $this->replaceSelectAliases($cnt_query);
     
     			// select count
     			$cnt_query = 'SELECT COUNT(1) AS TMP_ROWS_CNT FROM ('.$cnt_query.') xxx';
     			$cnt = $connection->queryScalar($cnt_query);
     		}
     */
     $connection = \Bitrix\Main\Application::getConnection();
     $result = $connection->query($query);
     $result->setReplacedAliases($this->replaced_aliases);
     $this->last_query = $query;
     return $result;
 }
Example #2
0
 protected function query($build_parts)
 {
     // nosql support with new platform only
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/d7.php")) {
         // check nosql configuration
         $configuration = $this->init_entity->getConnection()->getConfiguration();
         if (isset($configuration['handlersocket']['read'])) {
             $nosqlConnectionName = $configuration['handlersocket']['read'];
             $nosqlConnection = \Bitrix\Main\Application::getInstance()->getDbConnectionPool()->getConnection($nosqlConnectionName);
             $isNosqlCapable = NosqlPrimarySelector::checkQuery($nosqlConnection, $this);
             if ($isNosqlCapable) {
                 $nosqlResult = NosqlPrimarySelector::relayQuery($nosqlConnection, $this);
                 $result = new \CDBResult();
                 $result->initFromArray($nosqlResult);
                 return $result;
             }
         }
     }
     foreach ($build_parts as $k => &$v) {
         if (strlen($v)) {
             $v = $k . ' ' . $v;
         }
     }
     if (!empty($this->options)) {
         foreach ($this->options as $opt => $value) {
             $build_parts = str_replace('%' . $opt . '%', $value, $build_parts);
         }
     }
     $query = join("\n", $build_parts);
     list($query, $replaced_aliases) = $this->replaceSelectAliases($query);
     if ($this->count_total || !is_null($this->offset)) {
         $cnt_body_elements = $build_parts;
         // remove order
         unset($cnt_body_elements['ORDER BY']);
         $cnt_query = join("\n", $cnt_body_elements);
         // remove long aliases
         list($cnt_query, ) = $this->replaceSelectAliases($cnt_query);
         // select count
         $cnt_query = 'SELECT COUNT(1) AS TMP_ROWS_CNT FROM (' . $cnt_query . ') xxx';
         $result = $this->DB->query($cnt_query);
         $result = $result->fetch();
         $cnt = $result["TMP_ROWS_CNT"];
     }
     if (empty($this->limit)) {
         $result = $this->DB->query($query);
         $result->arReplacedAliases = $replaced_aliases;
     } elseif (!empty($this->limit) && is_null($this->offset)) {
         $query = $this->DB->topSql($query, intval($this->limit));
         $result = $this->DB->query($query);
         $result->arReplacedAliases = $replaced_aliases;
     } else {
         // main query
         $result = new \CDBResult();
         $result->arReplacedAliases = $replaced_aliases;
         $db_limit = array('nPageSize' => $this->limit, 'iNumPage' => $this->offset ? $this->offset / $this->limit + 1 : 1, 'bShowAll' => true);
         $result->navQuery($query, $cnt, $db_limit);
     }
     $this->last_query = $query;
     return $result;
 }