From 00987feda1b9d4c4d19b41291275e00d5d519f9c Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 5 Jul 2013 14:05:42 +0200 Subject: fix insertIfNotExist return value, update doc and corresponding test --- lib/db.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index 4d6788f2bda..d5ef4248764 100644 --- a/lib/db.php +++ b/lib/db.php @@ -702,7 +702,7 @@ class OC_DB { * @brief Insert a row if a matching row doesn't exists. * @param string $table. The table to insert into in the form '*PREFIX*tableName' * @param array $input. An array of fieldname/value pairs - * @returns The return value from PDOStatementWrapper->execute() + * @returns int number of updated rows */ public static function insertIfNotExist($table, $input) { self::connect(); @@ -736,7 +736,7 @@ class OC_DB { . implode('`,`', array_keys($input)) . '`) VALUES(' . str_repeat('?,', count($input)-1).'? ' . ')'; } else { - return true; + return 0; //no rows updated } } elseif( $type == 'pgsql' || $type == 'oci' || $type == 'mysql' || $type == 'mssql') { $query = 'INSERT INTO `' .$table . '` (`' @@ -757,9 +757,6 @@ class OC_DB { } catch(PDOException $e) { OC_Template::printExceptionErrorPage( $e ); } - if ($result === 0) { - return true; - } return $result; } -- cgit v1.2.3 From 212ea0508d05f881d01df4f5b2ed38133bdff359 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 5 Jul 2013 15:39:57 +0200 Subject: update comment --- lib/db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index d5ef4248764..efea9e40a8c 100644 --- a/lib/db.php +++ b/lib/db.php @@ -1047,7 +1047,7 @@ class PDOStatementWrapper{ } /** - * make execute return the result instead of a bool + * make execute return the result or updated row count instead of a bool */ public function execute($input=array()) { if(OC_Config::getValue( "log_query", false)) { -- cgit v1.2.3