diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index fd3028279..9a166d091 100755 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -4592,7 +4592,7 @@ class e_admin_controller_ui extends e_admin_controller */ public function getParentChildQry($orderby=false) { - return 'SELECT SQL_CALC_FOUND_ROWS * FROM `#' .$this->getTableName(). '` '; + return 'SELECT * FROM `#' .$this->getTableName(). '` '; } /** @@ -5229,7 +5229,7 @@ class e_admin_controller_ui extends e_admin_controller //file_put_contents(e_LOG.'uiAjaxResponseFields.log', print_r($this->getFields(), true)."\n\n", FILE_APPEND); if($joinData) { - $qry = 'SELECT SQL_CALC_FOUND_ROWS ' . $tableSFields; + $qry = 'SELECT ' . $tableSFields; foreach($joinData as $jtable => $tparams) { // Select fields @@ -5287,7 +5287,7 @@ class e_admin_controller_ui extends e_admin_controller } else { - $qry = 'SELECT SQL_CALC_FOUND_ROWS ' . $tableSFields . ' FROM ' . $tableFrom; + $qry = 'SELECT ' . $tableSFields . ' FROM ' . $tableFrom; } } @@ -5437,7 +5437,10 @@ class e_admin_controller_ui extends e_admin_controller // Print to the debug interface (optional, can overload logs) - e107::getMessage()->addDebug('
' . $jsonDebugInfo . ''); + if(E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES) + { + e107::getMessage()->addDebug('
' . $jsonDebugInfo . ''); + } return $qry; @@ -6542,11 +6545,6 @@ class e_admin_ui extends e_admin_controller_ui $this->addTitle(); - // if($this->getQuery('filter_options')) - { - // var_dump($this); - // $this->addTitle("to-do"); // display filter option when active. - } } diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index d59b6831a..6305ba204 100755 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -3459,7 +3459,7 @@ class e_tree_model extends e_front_model // auto-load all if(!$this->getParam('db_query') && $this->getModelTable()) { - $this->setParam('db_query', 'SELECT'.(!$this->getParam('nocount') ? ' SQL_CALC_FOUND_ROWS' : '') + $this->setParam('db_query', 'SELECT'.(!$this->getParam('nocount') ? '' : '') .($this->getParam('db_cols') ? ' '.$this->getParam('db_cols') : ' *').' FROM #'.$this->getModelTable() .($this->getParam('db_joins') ? ' '.$this->getParam('db_joins') : '') .($this->getParam('db_where') ? ' WHERE '.$this->getParam('db_where') : '') @@ -3687,20 +3687,31 @@ class e_tree_model extends e_front_model */ protected function countResults($sql) { - $total = $sql->foundRows(); - $this->_total = is_int($total) ? $total : false; //requires SQL_CALC_FOUND_ROWS in query - see db handler + $qry = $this->getParam('db_query'); + + // @todo Move to $sql->foundRows(); + + $qry = str_replace('SQL_CALC_FOUND_ROWS', '', $qry); // Deprecated as of MySQL 8.0 if(false === $this->_total && $this->getModelTable() && !$this->getParam('nocount')) { - //SQL_CALC_FOUND_ROWS not found in the query, do one more query - // $this->_total = e107::getDb()->db_Count($this->getModelTable()); // fails with specific listQry + $countQry = preg_replace('/\s+LIMIT\s+\d+(\s*,\s*\d+)?\s*$/i', "", $qry); - // Calculates correct total when using filters and search. //XXX Optimize. - $countQry = preg_replace('/(LIMIT ([\d,\s])*)$/', "", $this->getParam('db_query')); + $QRY = "SELECT COUNT(*) AS e_tree_total FROM ($countQry) AS grouped_rows"; - $this->_total = e107::getDb()->gen($countQry); + $result = $sql->retrieve($QRY); + $total = $result['e_tree_total'] ?? 0; + + if(E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES) + { + e107::getMessage()->addDebug("Count Qry: ".str_replace('#',MPREFIX,$QRY)); + e107::getMessage()->addDebug("Count Total: $total"); + } + + $this->_total = (int) $total; } + return $this->_total; } diff --git a/e107_tests/tests/_data/e_admin_ui/_modifyListQrySearch/a1b5f76b94de63038b10913bf22b0538c30b1fb1.json b/e107_tests/tests/_data/e_admin_ui/_modifyListQrySearch/a1b5f76b94de63038b10913bf22b0538c30b1fb1.json index 1b9bdbd20..db43c4864 100644 --- a/e107_tests/tests/_data/e_admin_ui/_modifyListQrySearch/a1b5f76b94de63038b10913bf22b0538c30b1fb1.json +++ b/e107_tests/tests/_data/e_admin_ui/_modifyListQrySearch/a1b5f76b94de63038b10913bf22b0538c30b1fb1.json @@ -273,5 +273,5 @@ "listQry": "", "listQryBeforeFinal": "" }, - "expected": "SELECT SQL_CALC_FOUND_ROWS `#links`.* FROM `#links` WHERE `#links`.link_category = '3' ORDER BY link_category,link_order ASC" -} + "expected": "SELECT `#links`.* FROM `#links` WHERE `#links`.link_category = '3' ORDER BY link_category,link_order ASC" +}