From 8eaf842d19e4206e1c44e0eda44688ebfa1728ed Mon Sep 17 00:00:00 2001 From: Mark Newnham Date: Thu, 28 Nov 2019 15:15:17 -0700 Subject: adodb_strip_order_by() strips incorrectly if there are multiple order by statements #549 If the SQL statement passed to adodb_strip_order contains multiple order by statements, the incorrect one is stripped. This change ensures that only the last one is stripped Co-Authored-By: mustafa-soner-acar --- adodb-lib.inc.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'adodb-lib.inc.php') diff --git a/adodb-lib.inc.php b/adodb-lib.inc.php index d73c1e40..444ac04a 100644 --- a/adodb-lib.inc.php +++ b/adodb-lib.inc.php @@ -19,7 +19,12 @@ $ADODB_INCLUDED_LIB = 1; function adodb_strip_order_by($sql) { - $rez = preg_match('/(\sORDER\s+BY\s(?:[^)](?!LIMIT))*)/is', $sql, $arr); + $rez = preg_match_all('/(\sORDER\s+BY\s(?:[^)](?!LIMIT))*)/is', $sql, $arr); + if ($arr) + { + $tmp = array_pop($arr); + $arr = [1=>array_pop($tmp)]; + } if ($arr) if (strpos($arr[1], '(') !== false) { $at = strpos($sql, $arr[1]); @@ -39,6 +44,7 @@ function adodb_strip_order_by($sql) } else { $sql = str_replace($arr[1], '', $sql); } + return $sql; } -- cgit v1.3