DB: Revert [28814] and require a WHERE for wpdb::update().
see #26106. git-svn-id: https://develop.svn.wordpress.org/trunk@29664 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7c09b36829
commit
1cde8312b6
@ -1793,9 +1793,7 @@ class wpdb {
|
|||||||
$wheres[] = "`$field` = {$form}";
|
$wheres[] = "`$field` = {$form}";
|
||||||
}
|
}
|
||||||
|
|
||||||
$wheres = empty( $where ) ? '' : ( ' WHERE ' . implode( ' AND ', $wheres ) );
|
$sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres );
|
||||||
|
|
||||||
$sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . $wheres;
|
|
||||||
return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) );
|
return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,19 +438,24 @@ class Tests_DB extends WP_UnitTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* wpdb::update() requires a WHERE condition.
|
||||||
*
|
*
|
||||||
* @ticket 26106
|
* @ticket 26106
|
||||||
*/
|
*/
|
||||||
function test_empty_where() {
|
function test_empty_where_on_update() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
$show = $wpdb->show_errors(false);
|
||||||
$wpdb->update( $wpdb->posts, array( 'post_name' => 'burrito' ), array() );
|
$wpdb->update( $wpdb->posts, array( 'post_name' => 'burrito' ), array() );
|
||||||
|
|
||||||
$expected1 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito'";
|
$expected1 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito' WHERE ";
|
||||||
|
$this->assertNotEmpty( $wpdb->last_error );
|
||||||
$this->assertEquals( $expected1, $wpdb->last_query );
|
$this->assertEquals( $expected1, $wpdb->last_query );
|
||||||
|
|
||||||
$wpdb->update( $wpdb->posts, array( 'post_name' => 'burrito' ), array( 'post_status' => 'taco' ) );
|
$wpdb->update( $wpdb->posts, array( 'post_name' => 'burrito' ), array( 'post_status' => 'taco' ) );
|
||||||
|
|
||||||
$expected2 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito' WHERE `post_status` = 'taco'";
|
$expected2 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito' WHERE `post_status` = 'taco'";
|
||||||
|
$this->assertEmpty( $wpdb->last_error );
|
||||||
$this->assertEquals( $expected2, $wpdb->last_query );
|
$this->assertEquals( $expected2, $wpdb->last_query );
|
||||||
|
$wpdb->show_errors( $show );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user