Project

General

Profile

Actions

Anomalie #839

closed

MySQL (recent version) SQL syntax issue on Distinct list queries

Added by Régis about 6 years ago. Updated about 6 years ago.

Status:
Fermé
Priority:
Normal
Assignee:
Category:
general
Target version:
Start date:
04/17/2018
Due date:
% Done:

100%

Estimated time:
2.00 h
Resolution:

Description

We run a recent version of MySQL (5.7) and some queries on SQL_getNewsList were rejected. Some other queries may be affected also

Our patch on www/news/mysql.inc.php SQL_getNewsList is:

-  $q= "SELECT DISTINCT(news_id), LEFT(news_title, 60) AS news_title, news_title AS complete_news_title, ".
+  $q= "SELECT DISTINCT(news_id), ".
+        "news_range, news_date_crea, ".
+        "LEFT(news_title, 60) AS news_title, news_title AS complete_news_title, ".

DISTINCT queries using order by MUST have the order by fields in the select.

Simple example:

mysql> select version();
----------------------- | version() |
----------------------- | 5.7.21-0ubuntu0.16.04.1 |
-----------------------
1 row in set (0,00 sec)
mysql> SELECT DISTINCT, LEFT AS news_title FROM l21_news ORDER BY news_date_crea ASC;
ERROR 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'xxxxx.l21_news.news_date_crea' which is not in SELECT list; this is incompatible with DISTINCT
mysql> SELECT DISTINCT, news_date_crea, LEFT AS news_title FROM l21_news ORDER BY news_date_crea ASC;
----------------------------+-----------------+ | news_id | news_date_crea | news_title |
----------------------------+-----------------
(...)

Actions #1

Updated by Simon about 6 years ago

  • Assignee set to Simon
  • Target version set to 2.1
  • Estimated time set to 2.00 h

Hi Regis,

I'm aware of this bug. This is due to new MySQL default settings :
https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_only_full_group_by

For now, the application itself run the following query to prevent bug to occur :

SET SESSION sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

see code : http://dev.linea21.com/projects/linea21/repository/entry/trunk/v2.0/class/system/class.mysql.php#L85

Maybe your MySQL current settings does not allow SESSION instructions !? I'm running exactly the same version you run under Ubuntu 16.04 as well and have no problem.

Anyway, we will adapt queries for the next Linea21 version.

Thanks for reporting,

Actions #2

Updated by Régis about 6 years ago

OK, so I'll check deeper on why this session settings were not applied...

Actions #3

Updated by Simon about 6 years ago

  • Status changed from Nouveau to Fermé
  • % Done changed from 0 to 100

Applied in changeset linea21|r3340.

Actions

Also available in: Atom PDF