Plugin Directory

Changeset 546689


Ignore:
Timestamp:
05/20/2012 07:24:06 PM (14 years ago)
Author:
hawk__
Message:

Protect against a possible collision when handling 'ON DUPLICATE KEY'

File:
1 edited

Legend:

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

    r546644 r546689  
    314314            if( false !== $pos = strpos( $sql, 'ON DUPLICATE KEY'))
    315315            {
    316                 // Remove 'ON DUPLICATE KEY UPDATE...' and following
    317                 $sql = substr( $sql, 0, $pos);
    318316                // Get the elements we need (table name, first field, corresponding value)
    319317                $pattern = '/INSERT INTO\s+([^\(]+)\(([^,]+)[^\(]+VALUES\s*\(([^,]+)/';
    320318                preg_match($pattern, $sql, $matches);
    321                 $sql = 'DELETE FROM '.$matches[1].' WHERE '.$matches[2].' = '.$matches[3].';'.$sql;
     319                $table = trim( $matches[1], ' `');
     320                if( !in_array(trim($matches[1],'` '), array($wpdb->posts,$wpdb->comments)))
     321                {
     322                    // Remove 'ON DUPLICATE KEY UPDATE...' and following
     323                    $sql = substr( $sql, 0, $pos);
     324                    // Add a delete query to handle the maybe existing data
     325                    $sql = 'DELETE FROM '.$table.' WHERE '.$matches[2].' = '.$matches[3].';'.$sql;
     326                }
    322327            }
    323328           
Note: See TracChangeset for help on using the changeset viewer.