Jump to content

1.4.0.17 - Bug dans classes admin/tab.php


Recommended Posts

Bonjour,

Il y a deux erreurs dans la classe adminTAb qui gère le back office!

Dans la fonction getList()

Cette fonction effectue deux requêtes SELECT dans la base pour remplir la table.
Le deuxième SELECT doit renvoyer le nombre de lignes pour la pagination.

Par erreur, elle renvoie aussi la totalité des valeurs.

De plus si on utilise des clauses comme de regroupement GROUP BY, associé par exemple à une requête utilisant MAX(colonne), elle renvoie uniquement la première valeur du nombre de lignes regroupé, au lieu du nombre total de résultats

Je l'utilise pour lister la dernière adresse ip utilisée dans une liste de paniers, ce qui correspond à un regroupement dans la table jointe connections par guest.

Solution : remplacer :

        /* Query in order to get results with all fields */
       $sql = 'SELECT SQL_CALC_FOUND_ROWS
           '.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
           '.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').'
           FROM `'._DB_PREFIX_.$sqlTable.'` a
           '.($this->lang ? 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'` AND b.`id_lang` = '.(int)($id_lang).')' : '').'
           '.(isset($this->_join) ? $this->_join.' ' : '').'
           WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').(isset($this->_filter) ? $this->_filter : '').'
           '.(isset($this->_group) ? $this->_group.' ' : '').'
           '.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').(isset($this->_having) ? $this->_having.' ' : '').'
           ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).
           ($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').'
           LIMIT '.(int)($start).','.(int)($limit);

       $this->_list = Db::getInstance()->ExecuteS($sql);
       $this->_listTotal = Db::getInstance()->getValue('SELECT COUNT(*),
           '.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
           '.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').'
           FROM `'._DB_PREFIX_.$sqlTable.'` a
           '.($this->lang ? 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'` AND b.`id_lang` = '.(int)($id_lang).')' : '').'
           '.(isset($this->_join) ? $this->_join.' ' : '').'
           WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').(isset($this->_filter) ? $this->_filter : '').'
           '.(isset($this->_group) ? $this->_group.' ' : '').'
           '.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').(isset($this->_having) ? $this->_having.' ' : '').'
           ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).
           ($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : ''));
   }




par


        /* Query in order to get results with all fields */
       $sql = 'SELECT SQL_CALC_FOUND_ROWS
           '.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
           '.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').'
           FROM `'._DB_PREFIX_.$sqlTable.'` a
           '.($this->lang ? 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'` AND b.`id_lang` = '.(int)($id_lang).')' : '').'
           '.(isset($this->_join) ? $this->_join.' ' : '').'
           WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').(isset($this->_filter) ? $this->_filter : '').'
           '.(isset($this->_group) ? $this->_group.' ' : '').'
           '.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').(isset($this->_having) ? $this->_having.' ' : '').'
           ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).
           ($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').'
           LIMIT '.(int)($start).','.(int)($limit);


       $this->_list = Db::getInstance()->ExecuteS($sql);

       $this->_listTotal = Db::getInstance()->getRow('SELECT FOUND_ROWS()');
       $this->_listTotal = $this->_listTotal['FOUND_ROWS()'];

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...