public function executeEx(&$totalRows, $cacheOptions = null)
{
self::$_hiddenParamNumber = 0;
$copy = clone $this;
$this->_sql = $this->_buildSql();
if ($cacheOptions !== null) {
$_cacheOptions = $this->_getCacheOptions($cacheOptions);
$result = $this->modelsCache->get($_cacheOptions['key']);
if ($result !== false) {
$result = json_decode($result, true);
$totalRows = $result['total'];
return $result['rows'];
}
}
try {
$result = $this->modelsManager->getReadConnection(end($this->_models))->fetchAll($this->_sql, $this->_bind);
} catch (\Exception $e) {
throw new QueryBuilderException(':message: :sql', ['message' => $e->getMessage(), 'sql' => $this->_sql]);
}
if (!$this->_limit) {
$totalRows = count($result);
} else {
if (count($result) % $this->_limit === 0) {
$totalRows = $copy->_getTotalRows();
} else {
$totalRows = $this->_offset + count($result);
}
}
if (isset($_cacheOptions)) {
$this->modelsCache->set($_cacheOptions['key'], json_encode($this->_buildCacheData($result, $totalRows), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), $_cacheOptions['ttl']);
}
return $result;
}