Plugin Directory

Changeset 436140


Ignore:
Timestamp:
09/10/2011 10:11:30 PM (15 years ago)
Author:
hawk__
Message:

Modified the method for counting rows as mysql counts avery rows ignoring the limit clause

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postgresql-for-wordpress/trunk/pg4wp/driver_pgsql.php

    r429282 r436140  
    2020    $GLOBALS['pg4wp_version'] = '7.0';
    2121    $GLOBALS['pg4wp_result'] = 0;
    22     $GLOBALS['pg4wp_numrows'] = '10';
     22    $GLOBALS['pg4wp_numrows_query'] = '';
    2323    $GLOBALS['pg4wp_ins_table'] = '';
    2424    $GLOBALS['pg4wp_ins_field'] = '';
     
    143143            }
    144144            elseif( false !== strpos($sql, 'FOUND_ROWS()'))
    145                 return $GLOBALS['pg4wp_numrows'];
     145            {
     146                // Here we need to convert the latest query into a COUNT query
     147                $sql = $GLOBALS['pg4wp_numrows_query'];
     148                echo '<pre>'.$sql.'</pre>';
     149                // Remove any LIMIT ... clause (this is the blocking part)
     150                $pattern = '/\s+LIMIT.+/';
     151                $sql = preg_replace( $pattern, '', $sql);
     152                echo '<pre>'.$sql.'</pre>';
     153                // Now add the COUNT() statement
     154                $pattern = '/SELECT\s+([^\s]+)\s+(FROM.+)/';
     155                $sql = preg_replace( $pattern, 'SELECT COUNT($1) $2', $sql);
     156                echo '<pre>'.$sql.'</pre>';
     157            }
    146158           
    147159            // Handle COUNT(*)...ORDER BY...
     
    388400        if( $catchnumrows && $GLOBALS['pg4wp_result'] !== false)
    389401        {
    390             $GLOBALS['pg4wp_numrows'] = pg_num_rows( $GLOBALS['pg4wp_result']);
     402            $GLOBALS['pg4wp_numrows_query'] = $sql;
    391403            if( PG4WP_DEBUG)
    392                 error_log( "Catched number of rows for :\n$sql\nResult is :".$GLOBALS['pg4wp_numrows']."\n---------------------\n", 3, PG4WP_LOG.'pg4wp_NUMROWS.log');
     404                error_log( "Number of rows required for :\n$sql\n---------------------\n", 3, PG4WP_LOG.'pg4wp_NUMROWS.log');
    393405        }
    394406        return $GLOBALS['pg4wp_result'];
Note: See TracChangeset for help on using the changeset viewer.