diff options
| author | Mark Newnham <mark@newnhams.com> | 2019-11-28 15:15:17 -0700 |
|---|---|---|
| committer | Mark Newnham <mark@newnhams.com> | 2019-11-28 15:15:17 -0700 |
| commit | 8eaf842d19e4206e1c44e0eda44688ebfa1728ed (patch) | |
| tree | 74cbaac1881b60cfe29e2ca4251cc814f4efad4a /adodb-lib.inc.php | |
| parent | 02192183acaa167d7986e0c143112c725ca8e552 (diff) | |
| download | adodb-8eaf842d19e4206e1c44e0eda44688ebfa1728ed.tar.gz adodb-8eaf842d19e4206e1c44e0eda44688ebfa1728ed.tar.bz2 adodb-8eaf842d19e4206e1c44e0eda44688ebfa1728ed.zip | |
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 <mustafa-soner-acar@users.noreply.github.com>
Diffstat (limited to 'adodb-lib.inc.php')
| -rw-r--r-- | adodb-lib.inc.php | 8 |
1 files changed, 7 insertions, 1 deletions
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; } |
