From 1cde8312b6c12e91cce619a006f6bf35c104d66c Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 2 Sep 2014 04:55:17 +0000 Subject: [PATCH] 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 --- src/wp-includes/wp-db.php | 4 +--- tests/phpunit/tests/db.php | 9 +++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index 08a6b8c72f..f30ad79146 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -1793,9 +1793,7 @@ class wpdb { $wheres[] = "`$field` = {$form}"; } - $wheres = empty( $where ) ? '' : ( ' WHERE ' . implode( ' AND ', $wheres ) ); - - $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . $wheres; + $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres ); return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) ); } diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index 19db983075..e66646393e 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -438,19 +438,24 @@ class Tests_DB extends WP_UnitTestCase { } /** + * wpdb::update() requires a WHERE condition. * * @ticket 26106 */ - function test_empty_where() { + function test_empty_where_on_update() { global $wpdb; + $show = $wpdb->show_errors(false); $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 ); $wpdb->update( $wpdb->posts, array( 'post_name' => 'burrito' ), array( '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 ); + $wpdb->show_errors( $show ); } }