Changed SQL_CALC_FOUND_ROWS handling

git-svn-id: https://plugins.svn.wordpress.org/postgresql-for-wordpress/trunk@419551 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
hawk__
2011-08-04 23:01:39 +00:00
parent 254f793473
commit d9d576aa99
2 changed files with 10 additions and 8 deletions

View File

@@ -118,17 +118,11 @@
if( false !== strpos($sql, 'SQL_CALC_FOUND_ROWS')) if( false !== strpos($sql, 'SQL_CALC_FOUND_ROWS'))
{ {
$catchnumrows = true; $catchnumrows = true;
$sql = str_replace('GROUP BY '.$wpdb->prefix.'posts.ID', '' , $sql);
$GLOBALS['pg4wp_numrows'] = str_replace( 'SQL_CALC_FOUND_ROWS', 'DISTINCT', $sql);
$GLOBALS['pg4wp_numrows'] = preg_replace( '/SELECT DISTINCT.+FROM ('.$wpdb->prefix.'posts)/', 'SELECT DISTINCT "ID" FROM $1', $GLOBALS['pg4wp_numrows']);
$GLOBALS['pg4wp_numrows'] = preg_replace( '/SELECT(.+)FROM/', 'SELECT COUNT($1) FROM', $GLOBALS['pg4wp_numrows']);
$GLOBALS['pg4wp_numrows'] = preg_replace( '/(ORDER BY|LIMIT).+/', '', $GLOBALS['pg4wp_numrows']);
$sql = str_replace('SQL_CALC_FOUND_ROWS', '', $sql); $sql = str_replace('SQL_CALC_FOUND_ROWS', '', $sql);
} }
elseif( false !== strpos($sql, 'FOUND_ROWS()')) elseif( false !== strpos($sql, 'FOUND_ROWS()'))
{ return $GLOBALS['pg4wp_numrows'];
$sql = $GLOBALS['pg4wp_numrows'];
}
// Handle COUNT(*)...ORDER BY... // Handle COUNT(*)...ORDER BY...
$sql = preg_replace( '/COUNT(.+)ORDER BY.+/', 'COUNT$1', $sql); $sql = preg_replace( '/COUNT(.+)ORDER BY.+/', 'COUNT$1', $sql);
@@ -374,6 +368,12 @@
if( false === strpos($err, 'relation "'.$wpdb->prefix.'options"')) if( false === strpos($err, 'relation "'.$wpdb->prefix.'options"'))
error_log("Error running :\n$initial\n---- converted to ----\n$sql\n----\n$err\n---------------------\n", 3, PG4WP_LOG.'pg4wp_errors.log'); error_log("Error running :\n$initial\n---- converted to ----\n$sql\n----\n$err\n---------------------\n", 3, PG4WP_LOG.'pg4wp_errors.log');
if( $catchnumrows && $GLOBALS['pg4wp_result'] !== false)
{
$GLOBALS['pg4wp_numrows'] = pg_num_rows( $GLOBALS['pg4wp_result']);
if( PG4WP_DEBUG)
error_log( "Catched number of rows for :\n$sql\nResult is :".$GLOBALS['pg4wp_numrows']."\n---------------------\n", 3, PG4WP_LOG.'pg4wp_NUMROWS.log');
}
return $GLOBALS['pg4wp_result']; return $GLOBALS['pg4wp_result'];
} }

View File

@@ -50,6 +50,8 @@ There is no screenshot for this plugin
== Changelog == == Changelog ==
* Some code optimizations
= 1.2.0b1 = = 1.2.0b1 =
* Somewhat improved Wordpress plugins compatibility * Somewhat improved Wordpress plugins compatibility
* Added 'PG4WP_INSECURE' parameter for future use * Added 'PG4WP_INSECURE' parameter for future use