/** * Returns the search results for the given SQL statement. * * @param \Aimeos\MW\DB\Connection\Iface $conn Database connection * @param $sql SQL statement * @return \Aimeos\MW\DB\Result\Iface Search result object */ protected function getSearchResults(\Aimeos\MW\DB\Connection\Iface $conn, $sql) { $statement = $conn->create($sql); $this->getContext()->getLogger()->log(__METHOD__ . ': SQL statement: ' . $statement, \Aimeos\MW\Logger\Base::DEBUG); $results = $statement->execute(); return $results; }
/** * Returns the search result object for the given SQL statement. * * @param \Aimeos\MW\DB\Connection\Iface $conn Database connection * @param string $sql SQL-statement to execute * @return \Aimeos\MW\DB\Result\Iface Returns db result set from given sql statment */ protected function getSearchResults(\Aimeos\MW\DB\Connection\Iface $conn, $sql) { $context = $this->getContext(); $siteId = $context->getLocale()->getSiteId(); $statement = $conn->create($sql); $statement->bind(1, $siteId, \Aimeos\MW\DB\Statement\Base::PARAM_INT); $context->getLogger()->log(__METHOD__ . ': SQL statement: ' . $statement, \Aimeos\MW\Logger\Base::DEBUG); return $statement->execute(); }
/** * Returns the search result of the statement combined with the given criteria. * * @param \Aimeos\MW\DB\Connection\Iface $conn Database connection * @param \Aimeos\MW\Criteria\Iface $search Search criteria object * @param string $cfgPathSearch Path to SQL statement in configuration for searching * @param string $cfgPathCount Path to SQL statement in configuration for counting * @param string[] $required Additional search keys to add conditions for even if no conditions are available * @param integer|null $total Contains the number of all records matching the criteria if not null * @param integer $sitelevel Constant from \Aimeos\MShop\Locale\Manager\Base for defining which site IDs should be used for searching * @param array $plugins Associative list of item keys and plugin objects implementing \Aimeos\MW\Criteria\Plugin\Iface * @return \Aimeos\MW\DB\Result\Iface SQL result object for accessing the found records * @throws \Aimeos\MShop\Exception if no number of all matching records is available */ protected function searchItemsBase(\Aimeos\MW\DB\Connection\Iface $conn, \Aimeos\MW\Criteria\Iface $search, $cfgPathSearch, $cfgPathCount, array $required, &$total = null, $sitelevel = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL, array $plugins = array()) { $joins = array(); $conditions = $search->getConditions(); $attributes = $this->getSearchAttributes(); $siteIds = $this->getSiteIds($sitelevel); $keys = $this->getCriteriaKeyList($search, $required); $basekey = array_shift($required); foreach ($keys as $key) { if ($key !== $basekey) { $joins = array_merge($joins, $this->getJoins($attributes, $key)); } } $cond = $this->getSearchSiteConditions($search, $keys, $attributes, $siteIds); if ($conditions !== null) { $cond[] = $conditions; } $search = clone $search; $search->setConditions($search->combine('&&', $cond)); $types = $this->getSearchTypes($attributes); $translations = $this->getSearchTranslations($attributes); $find = array(':joins', ':cond', ':start', ':size'); $replace = array(implode("\n", array_unique($joins)), $search->getConditionString($types, $translations, $plugins), $search->getSliceStart(), $search->getSliceSize()); if (count($search->getSortations()) > 0) { $keys[] = 'orderby'; $find[] = ':order'; $replace[] = $search->getSortationString($types, $translations); $keys[] = 'columns'; $find[] = ':columns'; $replace[] = $search->getColumnString($search->getSortations(), $translations); } if ($total !== null) { $sql = new \Aimeos\MW\Template\SQL($this->getSqlConfig($cfgPathCount)); $sql->replace($find, $replace)->enable($keys); $time = microtime(true); $stmt = $conn->create($sql->str()); $results = $stmt->execute(); $row = $results->fetch(); $results->finish(); $this->context->getLogger()->log(__METHOD__ . '(' . (microtime(true) - $time) * 1000 . 'ms): SQL statement: ' . $stmt, \Aimeos\MW\Logger\Base::DEBUG); if ($row === false) { throw new \Aimeos\MShop\Exception(sprintf('Total results value not found')); } $total = (int) $row['count']; } $sql = new \Aimeos\MW\Template\SQL($this->getSqlConfig($cfgPathSearch)); $sql->replace($find, $replace)->enable($keys); $time = microtime(true); $stmt = $conn->create($sql->str()); $results = $stmt->execute(); $this->context->getLogger()->log(__METHOD__ . '(' . (microtime(true) - $time) * 1000 . 'ms): SQL statement: ' . $stmt, \Aimeos\MW\Logger\Base::DEBUG); return $results; }
/** * Returns the search result object for the given SQL statement. * * @param \Aimeos\MW\DB\Connection\Iface $conn Database connection * @param string $sql SQL-statement to execute * @return \Aimeos\MW\DB\Result\Iface Returns db result set from given sql statment */ protected function getSearchResults(\Aimeos\MW\DB\Connection\Iface $conn, $sql) { $context = $this->getContext(); $statement = $conn->create($sql); try { $statement->bind(1, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT); } catch (\Exception $e) { $statement->bind(1, null, \Aimeos\MW\DB\Statement\Base::PARAM_INT); } return $statement->execute(); }