rdbms: make * consistently act like in select/insertSelect methods
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 1 Oct 2018 21:31:53 +0000 (14:31 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 1 Oct 2018 21:31:53 +0000 (14:31 -0700)
This now matches the documentation of insertSelect()

Bug: T202553
Change-Id: Ie6602fdd3b48b9136de7c65289c85ced5f5f2f1d

includes/libs/rdbms/database/Database.php
includes/libs/rdbms/database/IDatabase.php
tests/phpunit/includes/libs/rdbms/database/DatabaseSQLTest.php

index f37364f..5c0a8c7 100644 (file)
@@ -1742,7 +1742,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        $conds = '';
                }
 
-               if ( $conds === '' ) {
+               if ( $conds === '' || $conds === '*' ) {
                        $sql = "SELECT $startOpts $fields $from $useIndex $ignoreIndex $preLimitTail";
                } elseif ( is_string( $conds ) ) {
                        $sql = "SELECT $startOpts $fields $from $useIndex $ignoreIndex " .
index f97db3a..b1582a1 100644 (file)
@@ -670,6 +670,8 @@ interface IDatabase {
         * Escaping of untrusted input used in values of numeric keys should be done via
         * IDatabase::addQuotes()
         *
+        * Use an empty array, string, or '*' to update all rows.
+        *
         * @param string|array $options
         *
         * Optional: Array of query options. Boolean options are specified by
index 0cb35b4..600e0d3 100644 (file)
@@ -674,9 +674,9 @@ class DatabaseSQLTest extends PHPUnit\Framework\TestCase {
                                "INSERT INTO insert_table " .
                                        "(field_insert,field) " .
                                        "SELECT field_select,field2 " .
-                                       "FROM select_table WHERE *",
+                                       "FROM select_table",
                                "SELECT field_select AS field_insert,field2 AS field " .
-                               "FROM select_table WHERE *   FOR UPDATE",
+                               "FROM select_table      FOR UPDATE",
                                "INSERT INTO insert_table (field_insert,field) VALUES ('0','1')"
                        ],
                        [
@@ -755,7 +755,7 @@ class DatabaseSQLTest extends PHPUnit\Framework\TestCase {
                        __METHOD__
                );
                $this->assertLastSqlDb( implode( '; ', [
-                       'SELECT field2 AS field FROM select_table WHERE *   FOR UPDATE',
+                       'SELECT field2 AS field FROM select_table      FOR UPDATE',
                        'BEGIN',
                        "INSERT INTO insert_table (field) VALUES ('" . implode( "'),('", range( 0, 9999 ) ) . "')",
                        "INSERT INTO insert_table (field) VALUES ('" . implode( "'),('", range( 10000, 19999 ) ) . "')",