summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-03-16 10:31:36 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-03-16 10:31:36 +0100
commit997a7a26685215ab1bba8d6f64d30bb8f97b85a2 (patch)
treecb23fe2431c69c6d6a8548d03a2e20fede814f16 /lib/public
parent1e0d8f1774747871c8cab03bccc03cd84ee96764 (diff)
parentfefcbb966b6c41b9440f67b8121b9c97e1ce7df0 (diff)
downloadnextcloud-server-997a7a26685215ab1bba8d6f64d30bb8f97b85a2.tar.gz
nextcloud-server-997a7a26685215ab1bba8d6f64d30bb8f97b85a2.zip
Merge pull request #14766 from owncloud/fix-insertifnotexists-poc
Allow specifying the compare-array for insertIfNotExists()
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/db.php24
-rw-r--r--lib/public/idbconnection.php26
2 files changed, 18 insertions, 32 deletions
diff --git a/lib/public/db.php b/lib/public/db.php
index e8fc817106e..595ecd66bdc 100644
--- a/lib/public/db.php
+++ b/lib/public/db.php
@@ -48,24 +48,18 @@ class DB {
}
/**
- * Insert a row if a matching row doesn't exists.
- * @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix
- * @param array $input
- *
- * The input array if in the form:
+ * Insert a row if the matching row does not exists.
*
- * array ( 'id' => array ( 'value' => 6,
- * 'key' => true
- * ),
- * 'name' => array ('value' => 'Stoyan'),
- * 'family' => array ('value' => 'Stefanov'),
- * 'birth_date' => array ('value' => '1975-06-20')
- * );
- * @return bool
+ * @param string $table The table name (will replace *PREFIX* with the actual prefix)
+ * @param array $input data that should be inserted into the table (column name => value)
+ * @param array|null $compare List of values that should be checked for "if not exists"
+ * If this is null or an empty array, all keys of $input will be compared
+ * @return int number of inserted rows
+ * @throws \Doctrine\DBAL\DBALException
*
*/
- public static function insertIfNotExist($table, $input) {
- return(\OC_DB::insertIfNotExist($table, $input));
+ public static function insertIfNotExist($table, $input, array $compare = null) {
+ return \OC::$server->getDatabaseConnection()->insertIfNotExist($table, $input, $compare);
}
/**
diff --git a/lib/public/idbconnection.php b/lib/public/idbconnection.php
index 0d3274d90eb..1117c2da9b2 100644
--- a/lib/public/idbconnection.php
+++ b/lib/public/idbconnection.php
@@ -77,24 +77,16 @@ interface IDBConnection {
public function lastInsertId($table = null);
/**
- * Insert a row if a matching row doesn't exists.
- * @param string $table The table name (will replace *PREFIX*) to perform the replace on.
- * @param array $input
- * @throws \OC\HintException
+ * Insert a row if the matching row does not exists.
*
- * The input array if in the form:
- *
- * array ( 'id' => array ( 'value' => 6,
- * 'key' => true
- * ),
- * 'name' => array ('value' => 'Stoyan'),
- * 'family' => array ('value' => 'Stefanov'),
- * 'birth_date' => array ('value' => '1975-06-20')
- * );
- * @return bool
- *
- */
- public function insertIfNotExist($table, $input);
+ * @param string $table The table name (will replace *PREFIX* with the actual prefix)
+ * @param array $input data that should be inserted into the table (column name => value)
+ * @param array|null $compare List of values that should be checked for "if not exists"
+ * If this is null or an empty array, all keys of $input will be compared
+ * @return int number of inserted rows
+ * @throws \Doctrine\DBAL\DBALException
+ */
+ public function insertIfNotExist($table, $input, array $compare = null);
/**
* Start a transaction