rdbms: Add support for ALL_ROWS in two query builders
Delete and Update query builders set the ->where( Database::ALL_ROWS ) as [ Database::ALL_ROWS ] internally and this makes sure they are basically treated as condition simply being Database::ALL_ROWS Bug: T332329 Change-Id: I79c308a8951f99869ffa09bd47c8e9bdf23f312e
This commit is contained in:
parent
e1f64c1bc0
commit
7cf42e26c9
4 changed files with 38 additions and 3 deletions
|
|
@ -1508,7 +1508,7 @@ class SQLPlatform implements ISQLPlatform {
|
|||
|
||||
$condsSql = '';
|
||||
$cleanCondsSql = '';
|
||||
if ( $conds !== self::ALL_ROWS ) {
|
||||
if ( $conds !== self::ALL_ROWS && $conds !== [ self::ALL_ROWS ] ) {
|
||||
$cleanCondsSql = ' WHERE ' . $this->scrubConditions( $conds );
|
||||
if ( is_array( $conds ) ) {
|
||||
$conds = $this->makeList( $conds, self::LIST_AND );
|
||||
|
|
@ -1541,7 +1541,7 @@ class SQLPlatform implements ISQLPlatform {
|
|||
$opts = $this->makeUpdateOptions( $options );
|
||||
$sql = "UPDATE $opts $table SET " . $this->makeList( $set, self::LIST_SET );
|
||||
|
||||
if ( $conds && $conds !== self::ALL_ROWS ) {
|
||||
if ( $conds && $conds !== self::ALL_ROWS && $conds !== [ self::ALL_ROWS ] ) {
|
||||
if ( is_array( $conds ) ) {
|
||||
$conds = $this->makeList( $conds, self::LIST_AND );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -508,6 +508,16 @@ class SQLPlatformTest extends PHPUnit\Framework\TestCase {
|
|||
"SET field = other" .
|
||||
",field2 = 'text2'"
|
||||
],
|
||||
[
|
||||
[
|
||||
'table' => 'table',
|
||||
'values' => [ 'field = other', 'field2' => 'text2' ],
|
||||
'conds' => [ '*' ],
|
||||
],
|
||||
"UPDATE table " .
|
||||
"SET field = other" .
|
||||
",field2 = 'text2'"
|
||||
],
|
||||
[
|
||||
[
|
||||
'table' => 'table',
|
||||
|
|
@ -537,7 +547,7 @@ class SQLPlatformTest extends PHPUnit\Framework\TestCase {
|
|||
"UPDATE table " .
|
||||
"SET field = other" .
|
||||
",field2 = 'text2'",
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -619,6 +629,14 @@ class SQLPlatformTest extends PHPUnit\Framework\TestCase {
|
|||
"DELETE FROM table",
|
||||
"DELETE FROM table",
|
||||
],
|
||||
[
|
||||
[
|
||||
'table' => 'table',
|
||||
'conds' => [ '*' ],
|
||||
],
|
||||
"DELETE FROM table",
|
||||
"DELETE FROM table",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Wikimedia\Rdbms\DeleteQueryBuilder;
|
||||
use Wikimedia\Rdbms\Platform\ISQLPlatform;
|
||||
|
||||
/**
|
||||
* @covers \Wikimedia\Rdbms\DeleteQueryBuilder
|
||||
|
|
@ -44,6 +45,13 @@ class DeleteQueryBuilderTest extends PHPUnit\Framework\TestCase {
|
|||
$this->assertSQL( 'DELETE FROM 1 WHERE k = \'v1\' AND (k = \'v2\')', __METHOD__ );
|
||||
}
|
||||
|
||||
public function testCondsAllRows() {
|
||||
$this->dqb
|
||||
->table( 'a' )
|
||||
->where( ISQLPlatform::ALL_ROWS );
|
||||
$this->assertSQL( 'DELETE FROM a', __METHOD__ );
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
$this->dqb->delete( 't' )->where( 'c' )->caller( __METHOD__ );
|
||||
$this->dqb->execute();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Wikimedia\Rdbms\Platform\ISQLPlatform;
|
||||
use Wikimedia\Rdbms\UpdateQueryBuilder;
|
||||
|
||||
/**
|
||||
|
|
@ -68,6 +69,14 @@ class UpdateQueryBuilderTest extends PHPUnit\Framework\TestCase {
|
|||
$this->assertSQL( 'UPDATE 1 SET a WHERE k = \'v1\' AND (k = \'v2\')', __METHOD__ );
|
||||
}
|
||||
|
||||
public function testCondsAllRows() {
|
||||
$this->uqb
|
||||
->update( '1' )
|
||||
->set( 'a' )
|
||||
->where( ISQLPlatform::ALL_ROWS );
|
||||
$this->assertSQL( 'UPDATE 1 SET a', __METHOD__ );
|
||||
}
|
||||
|
||||
public function testIgnore() {
|
||||
$this->uqb
|
||||
->update( 'f' )
|
||||
|
|
|
|||
Loading…
Reference in a new issue