summaryrefslogtreecommitdiffstats
path: root/lib/db.php
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2013-02-26 08:30:42 +0100
committerBart Visscher <bartv@thisnet.nl>2013-07-21 23:17:37 +0200
commit19b9c896340c572d9a42d033cd8824f33d18efa3 (patch)
tree5125454219343ed1686a634e91cd7d454007c006 /lib/db.php
parent58991150ab17846640907d43a6d4b0ff502d4986 (diff)
downloadnextcloud-server-19b9c896340c572d9a42d033cd8824f33d18efa3.tar.gz
nextcloud-server-19b9c896340c572d9a42d033cd8824f33d18efa3.zip
Move insertIfNotExist to Connection wrapper
Real implementation is in DB\Adapter* classes
Diffstat (limited to 'lib/db.php')
-rw-r--r--lib/db.php53
1 files changed, 1 insertions, 52 deletions
diff --git a/lib/db.php b/lib/db.php
index 0ad8a9b35d8..1f62326eea3 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -389,58 +389,7 @@ class OC_DB {
*/
public static function insertIfNotExist($table, $input) {
self::connect();
- $table = self::$connection->replaceTablePrefix( $table );
-
- if(is_null(self::$type)) {
- self::$type=OC_Config::getValue( "dbtype", "sqlite" );
- }
- $type = self::$type;
-
- $query = '';
- $inserts = array_values($input);
- // differences in escaping of table names ('`' for mysql) and getting the current timestamp
- if( $type == 'sqlite' || $type == 'sqlite3' ) {
- // NOTE: For SQLite we have to use this clumsy approach
- // otherwise all fieldnames used must have a unique key.
- $query = 'SELECT * FROM `' . $table . '` WHERE ';
- foreach($input as $key => $value) {
- $query .= '`' . $key . '` = ? AND ';
- }
- $query = substr($query, 0, strlen($query) - 5);
- try {
- $result = self::executeAudited($query, $inserts);
- } catch(DatabaseException $e) {
- OC_Template::printExceptionErrorPage( $e );
- }
-
- if((int)$result->numRows() === 0) {
- $query = 'INSERT INTO `' . $table . '` (`'
- . implode('`,`', array_keys($input)) . '`) VALUES('
- . str_repeat('?,', count($input)-1).'? ' . ')';
- } else {
- return 0; //no rows updated
- }
- } elseif( $type == 'pgsql' || $type == 'oci' || $type == 'mysql' || $type == 'mssql') {
- $query = 'INSERT INTO `' .$table . '` (`'
- . implode('`,`', array_keys($input)) . '`) SELECT '
- . str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative?
- . 'FROM `' . $table . '` WHERE ';
-
- foreach($input as $key => $value) {
- $query .= '`' . $key . '` = ? AND ';
- }
- $query = substr($query, 0, strlen($query) - 5);
- $query .= ' HAVING COUNT(*) = 0';
- $inserts = array_merge($inserts, $inserts);
- }
-
- try {
- $result = self::executeAudited($query, $inserts);
- } catch(\Doctrine\DBAL\DBALException $e) {
- OC_Template::printExceptionErrorPage( $e );
- }
-
- return $result;
+ return self::$connection->insertIfNotExist($table, $input);
}
/**