mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-30 17:57:13 +02:00
Convert HAVING without GROUP BY to WHERE
Fixes #9 Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This commit is contained in:
@ -329,6 +329,18 @@
|
||||
if( isset($wpdb) && false !== strpos( $sql, $wpdb->comments))
|
||||
$sql = str_replace(' comment_id ', ' comment_ID ', $sql);
|
||||
|
||||
// MySQL treats a HAVING clause without GROUP BY like WHERE
|
||||
if( false !== strpos($sql, 'HAVING') && false === strpos($sql, 'GROUP BY'))
|
||||
{
|
||||
if( false === strpos($sql, 'WHERE'))
|
||||
$sql = str_replace('HAVING', 'WHERE', $sql);
|
||||
else
|
||||
{
|
||||
$pattern = '/WHERE\s+(.*?)\s+HAVING\s+(.*?)(\s*(?:ORDER|LIMIT|PROCEDURE|INTO|FOR|LOCK|$))/';
|
||||
$sql = preg_replace( $pattern, 'WHERE ($1) AND ($2) $3', $sql);
|
||||
}
|
||||
}
|
||||
|
||||
// MySQL allows integers to be used as boolean expressions
|
||||
// where 0 is false and all other values are true.
|
||||
//
|
||||
|
Reference in New Issue
Block a user