From 51ec68a6231c577baa0890dbf8b4b91fe9c10ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 9 Sep 2013 21:06:48 +0200 Subject: [PATCH 1/3] Concatenate string in SQL instead of PHP --- apps/files/appinfo/update.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/files/appinfo/update.php b/apps/files/appinfo/update.php index 3503678e7c..d8886328d8 100644 --- a/apps/files/appinfo/update.php +++ b/apps/files/appinfo/update.php @@ -3,17 +3,17 @@ // 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::prepare( "UPDATE `*PREFIX*properties` + SET `propertyname` = $concat + WHERE `propertyname` LIKE '{%'" ); } //update from OC 3 From 72ca0a482b2b998c8f75f4dd3710c9635d8d6ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 12 Sep 2013 12:11:36 +0200 Subject: [PATCH 2/3] use doctrine to construct concat expression --- apps/files/appinfo/update.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/apps/files/appinfo/update.php b/apps/files/appinfo/update.php index d8886328d8..7ae0911465 100644 --- a/apps/files/appinfo/update.php +++ b/apps/files/appinfo/update.php @@ -3,14 +3,7 @@ // 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', '<')) { - // 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`"; - } + $concat = OC_DB::getConnection()->getDatabasePlatform()->getConcatExpression( "'{DAV:}'", "`propertyname`" ); $query = OC_DB::prepare( "UPDATE `*PREFIX*properties` SET `propertyname` = $concat WHERE `propertyname` LIKE '{%'" ); From 9ae829497a3e3a4ef535e9ed18f59233c0a4aa35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 1 Nov 2013 15:45:33 +0100 Subject: [PATCH 3/3] cleanup and actually execute the query --- apps/files/appinfo/update.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/files/appinfo/update.php b/apps/files/appinfo/update.php index 7ae0911465..f920f84216 100644 --- a/apps/files/appinfo/update.php +++ b/apps/files/appinfo/update.php @@ -3,10 +3,14 @@ // 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', '<')) { - $concat = OC_DB::getConnection()->getDatabasePlatform()->getConcatExpression( "'{DAV:}'", "`propertyname`" ); - $query = OC_DB::prepare( "UPDATE `*PREFIX*properties` - SET `propertyname` = $concat - WHERE `propertyname` LIKE '{%'" ); + $concat = OC_DB::getConnection()->getDatabasePlatform()-> + getConcatExpression( '\'{DAV:}\'', '`propertyname`' ); + $query = OC_DB::prepare(' + UPDATE `*PREFIX*properties` + SET `propertyname` = ' . $concat . ' + WHERE `propertyname` NOT LIKE \'{%\' + '); + $query->execute(); } //update from OC 3