DatabaseSqlite::insert: Fix affected row count
authorMarius Hoch <hoo@online.de>
Wed, 31 Oct 2018 15:32:46 +0000 (16:32 +0100)
committerMarius Hoch <hoo@online.de>
Wed, 31 Oct 2018 16:13:45 +0000 (17:13 +0100)
Follow up to 633eb437a3b808518469c6eaf4e86a436941d837

Bug: T208331
Change-Id: I142bb8c8abd43242d098932da212aa58323a0863

includes/libs/rdbms/database/DatabaseSqlite.php
tests/phpunit/includes/db/DatabaseSqliteTest.php

index 43776b5..7049df5 100644 (file)
@@ -654,6 +654,7 @@ class DatabaseSqlite extends Database {
                                $this->startAtomic( $fname, self::ATOMIC_CANCELABLE );
                                foreach ( $a as $v ) {
                                        parent::insert( $table, $v, "$fname/multi-row", $options );
+                                       $affectedRowCount += $this->affectedRows();
                                }
                                $this->endAtomic( $fname );
                        } catch ( Exception $e ) {
index 729b58c..78af11d 100644 (file)
@@ -403,6 +403,28 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
                $this->assertTrue( $db->close(), "closing database" );
        }
 
+       /**
+        * @covers DatabaseSqlite::insert
+        */
+       public function testInsertAffectedRows() {
+               $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
+               $db->query( 'CREATE TABLE testInsertAffectedRows ( foo )', __METHOD__ );
+
+               $insertion = $db->insert(
+                       'testInsertAffectedRows',
+                       [
+                               [ 'foo' => 10 ],
+                               [ 'foo' => 12 ],
+                               [ 'foo' => 1555 ],
+                       ],
+                       __METHOD__
+               );
+               $this->assertTrue( $insertion, "Insertion worked" );
+
+               $this->assertSame( 3, $db->affectedRows() );
+               $this->assertTrue( $db->close(), "closing database" );
+       }
+
        private function prepareTestDB( $version ) {
                static $maint = null;
                if ( $maint === null ) {