Skip to content

Commit e2c4246

Browse files
committed
SIP Trace: Improve "group by Call-ID" query
* be compatible with any SQL mode. This fixes: SELECT DISTINCT callid FROM sip_trace WHERE status='' AND direction='in' ORDER BY id DESC; ERROR 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'opensips.sip_trace.id' which is not in SELECT list; this is incompatible with DISTINCT * be consistent across different backends (e.g. don't sort the results differently with MySQL vs. Postgres) Fixes #83
1 parent 54f52c9 commit e2c4246

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Diff for: web/tools/system/siptrace/template/tracer.main.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,8 @@
134134

135135

136136
if ($_SESSION['grouped_results']) {
137-
if ($config->db_driver == "mysql")
138-
$sql = "SELECT DISTINCT callid FROM ".$table." WHERE status='' AND direction='in'".$sql_search." ORDER BY id DESC";
139-
else if ($config->db_driver == "pgsql")
140-
$sql = "SELECT DISTINCT ON (callid) callid FROM ".$table." WHERE status='' AND direction='in'".$sql_search." ORDER BY callid DESC";
141-
137+
$sql = "SELECT callid, MAX(id) AS mid FROM ".$table.
138+
" WHERE status='' AND direction='in'".$sql_search." GROUP BY callid ORDER BY mid DESC";
142139
$sql_cnt = "SELECT COUNT(DISTINCT(callid)) FROM ".$table." WHERE (1=1) ".$sql_search;
143140
} else {
144141
$sql = "SELECT id FROM ".$table." WHERE (1=1) ".$sql_search." ORDER BY id DESC";

0 commit comments

Comments
 (0)