[Pkg-owncloud-commits] [owncloud] 11/23: Make MySQL return "number of found rows" instead of number of "affected rows".

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 15:21:35 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 22c957d4757c86a2f4145a921350c8796ef12eeb
Author: Andreas Fischer <bantu at owncloud.com>
Date:   Wed Jul 16 14:35:47 2014 +0200

    Make MySQL return "number of found rows" instead of number of "affected rows".
---
 lib/private/db/connectionfactory.php |  8 ++++++-
 tests/lib/db.php                     | 41 ++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/lib/private/db/connectionfactory.php b/lib/private/db/connectionfactory.php
index 8f852cf..c132a23 100644
--- a/lib/private/db/connectionfactory.php
+++ b/lib/private/db/connectionfactory.php
@@ -60,7 +60,13 @@ class ConnectionFactory {
 		if (!isset($this->defaultConnectionParams[$normalizedType])) {
 			throw new \InvalidArgumentException("Unsupported type: $type");
 		}
-		return $this->defaultConnectionParams[$normalizedType];
+		$result = $this->defaultConnectionParams[$normalizedType];
+		if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) {
+			$result['driverOptions'] = array(
+				\PDO::MYSQL_ATTR_FOUND_ROWS => true,
+			);
+		}
+		return $result;
 	}
 
 	/**
diff --git a/tests/lib/db.php b/tests/lib/db.php
index 2fca67b..4b1a474 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -200,4 +200,45 @@ class Test_DB extends PHPUnit_Framework_TestCase {
 		}
 	}
 
+	public function testUpdateAffectedRowsNoMatch() {
+		$this->insertCardData('fullname1', 'uri1');
+		// The WHERE clause does not match any rows
+		$this->assertSame(0, $this->updateCardData('fullname3', 'uri2'));
+	}
+
+	public function testUpdateAffectedRowsDifferent() {
+		$this->insertCardData('fullname1', 'uri1');
+		// The WHERE clause matches a single row and the value we are updating
+		// is different from the one already present.
+		$this->assertSame(1, $this->updateCardData('fullname1', 'uri2'));
+	}
+
+	public function testUpdateAffectedRowsSame() {
+		$this->insertCardData('fullname1', 'uri1');
+		// The WHERE clause matches a single row and the value we are updating
+		// to is the same as the one already present. MySQL reports 0 here when
+		// the PDO::MYSQL_ATTR_FOUND_ROWS flag is not specified.
+		$this->assertSame(1, $this->updateCardData('fullname1', 'uri1'));
+	}
+
+	public function testUpdateAffectedRowsMultiple() {
+		$this->insertCardData('fullname1', 'uri1');
+		$this->insertCardData('fullname2', 'uri2');
+		// The WHERE clause matches two rows. One row contains a value that
+		// needs to be updated, the other one already contains the value we are
+		// updating to. MySQL reports 1 here when the PDO::MYSQL_ATTR_FOUND_ROWS
+		// flag is not specified.
+		$query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ?");
+		$this->assertSame(2, $query->execute(array('uri1')));
+	}
+
+	protected function insertCardData($fullname, $uri) {
+		$query = OC_DB::prepare("INSERT INTO `*PREFIX*{$this->table2}` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)");
+		$this->assertSame(1, $query->execute(array($fullname, $uri, uniqid())));
+	}
+
+	protected function updateCardData($fullname, $uri) {
+		$query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ? WHERE `fullname` = ?");
+		return $query->execute(array($uri, $fullname));
+	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list