]> source.dussan.org Git - nextcloud-server.git/commitdiff
Concatenate string in SQL instead of PHP
authorJörn Friedrich Dreyer <jfd@butonic.de>
Mon, 9 Sep 2013 19:06:48 +0000 (21:06 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Fri, 1 Nov 2013 14:44:01 +0000 (15:44 +0100)
apps/files/appinfo/update.php

index 3503678e7c7cef022039abc69d772666321e15fb..574b9c7b9636fa99f9785c20c5b9e39bd1e10a3e 100644 (file)
@@ -3,17 +3,19 @@
 // fix webdav properties,add namespace in front of the property, update for OC4.5
 $installedVersion=OCP\Config::getAppValue('files', 'installed_version');
 if (version_compare($installedVersion, '1.1.6', '<')) {
-       $query = OC_DB::prepare( 'SELECT `propertyname`, `propertypath`, `userid` FROM `*PREFIX*properties`' );
-       $result = $query->execute();
-       $updateQuery = OC_DB::prepare('UPDATE `*PREFIX*properties`'
-                                                               .' SET `propertyname` = ?'
-                                                               .' WHERE `userid` = ?'
-                                                               .' AND `propertypath` = ?');
-       while( $row = $result->fetchRow()) {
-               if ( $row['propertyname'][0] != '{' ) {
-                       $updateQuery->execute(array('{DAV:}' + $row['propertyname'], $row['userid'], $row['propertypath']));
-               }
+       // SQL92 string concatenation is ||, some of the DBMS don't know that
+       if (OC_Config::getValue('dbtype') === 'mysql') {
+               $concat = 'concat(\'{DAV:}\', `propertyname`)';
+       } else if (OC_Config::getValue('dbtype') === 'mssql') {
+               $concat = '\'{DAV:}\' + `propertyname`';
+       } else {
+               $concat = '\'{DAV:}\' || `propertyname`';
        }
+       $query = OC_DB::executeAudited('
+               UPDATE `*PREFIX*properties`
+               SET    `propertyname` = ' . $concat . '
+               WHERE  `propertyname` NOT LIKE \'{%\'
+       ');
 }
 
 //update from OC 3