Make WordPress Core

Changeset 29664


Ignore:
Timestamp:
09/02/2014 04:55:17 AM (10 years ago)
Author:
nacin
Message:

DB: Revert [28814] and require a WHERE for wpdb::update().

see #26106.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r29165 r29664  
    17941794        }
    17951795
    1796         $wheres = empty( $where ) ? '' : ( ' WHERE ' . implode( ' AND ', $wheres ) );
    1797 
    1798         $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . $wheres;
     1796        $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres );
    17991797        return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) );
    18001798    }
  • trunk/tests/phpunit/tests/db.php

    r28814 r29664  
    439439
    440440    /**
     441     * wpdb::update() requires a WHERE condition.
    441442     *
    442443     * @ticket 26106
    443444     */
    444     function test_empty_where() {
    445         global $wpdb;
     445    function test_empty_where_on_update() {
     446        global $wpdb;
     447        $show = $wpdb->show_errors(false);
    446448        $wpdb->update( $wpdb->posts, array( 'post_name' => 'burrito' ), array() );
    447449
    448         $expected1 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito'";
     450        $expected1 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito' WHERE ";
     451        $this->assertNotEmpty( $wpdb->last_error );
    449452        $this->assertEquals( $expected1, $wpdb->last_query );
    450453
     
    452455
    453456        $expected2 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito' WHERE `post_status` = 'taco'";
     457        $this->assertEmpty( $wpdb->last_error );
    454458        $this->assertEquals( $expected2, $wpdb->last_query );
     459        $wpdb->show_errors( $show );
    455460    }
    456461}
Note: See TracChangeset for help on using the changeset viewer.