From 378eef408236051f5bcb44011f20a51ed1fe3fe8 Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Tue, 13 Nov 2012 17:20:18 -0500 Subject: [PATCH] Use GCSSpecialQueries in sogo-tool rename-user Fixes #1924 The SQL syntax used by the former query would only work with postgresql and Oracle. --- SOPE/GDLContentStore/GCSSpecialQueries.m | 41 ++++++++++++++++++++++++ Tools/SOGoToolRenameUser.m | 19 +++++++---- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/SOPE/GDLContentStore/GCSSpecialQueries.m b/SOPE/GDLContentStore/GCSSpecialQueries.m index e99afbaf5..95ab3f814 100644 --- a/SOPE/GDLContentStore/GCSSpecialQueries.m +++ b/SOPE/GDLContentStore/GCSSpecialQueries.m @@ -110,6 +110,14 @@ return nil; } +- (NSString *) updateCPathInFolderInfo: (NSString *) tableName + withCPath2: (NSString *) c_path2 +{ + [self subclassResponsibility: _cmd]; + + return nil; +} + @end @@ -205,6 +213,17 @@ return types; } +- (NSString *) updateCPathInFolderInfo: (NSString *) tableName + withCPath2: (NSString *) c_path2 +{ + static NSString *sqlFolderFormat + = (@"UPDATE %@" + @" SET c_path = '/'||c_path1||'/'||c_path2||'/'||c_path3||'/'||c_path4" + @" WHERE c_path2 = '%@'"); + + return [NSString stringWithFormat: sqlFolderFormat, tableName, c_path2]; +} + @end // @@ -299,6 +318,17 @@ return types; } +- (NSString *) updateCPathInFolderInfo: (NSString *) tableName + withCPath2: (NSString *) c_path2 +{ + static NSString *sqlFolderFormat + = (@"UPDATE %@" + @" SET c_path = CONCAT('/', c_path1, '/', c_path2, '/', c_path3, '/', c_path4)" + @" WHERE c_path2 = '%@'"); + + return [NSString stringWithFormat: sqlFolderFormat, tableName, c_path2]; +} + @end // @@ -392,4 +422,15 @@ return types; } +- (NSString *) updateCPathInFolderInfo: (NSString *) tableName + withCPath2: (NSString *) c_path2 +{ + static NSString *sqlFolderFormat + = (@"UPDATE %@" + @" SET c_path = '/'||c_path1||'/'||c_path2||'/'||c_path3||'/'||c_path4" + @" WHERE c_path2 = '%@'"); + + return [NSString stringWithFormat: sqlFolderFormat, tableName, c_path2]; +} + @end diff --git a/Tools/SOGoToolRenameUser.m b/Tools/SOGoToolRenameUser.m index 860f98e0f..937424d76 100644 --- a/Tools/SOGoToolRenameUser.m +++ b/Tools/SOGoToolRenameUser.m @@ -35,6 +35,7 @@ #import #import #import +#import #import #import @@ -113,6 +114,7 @@ BOOL rc = NO; GCSFolderManager *fm; GCSChannelManager *cm; + GCSSpecialQueries *specialQueries; NSURL *folderLocation; EOAdaptorContext *ac; EOAdaptorChannel *fc; @@ -125,6 +127,7 @@ folderLocation = [fm folderInfoLocation]; fc = [cm acquireOpenChannelForURL: folderLocation]; ac = [fc adaptorContext]; + specialQueries = [fc specialQueries]; sqlFromUserID = [fromUserID asSafeSQLString]; sqlToUserID = [toUserID asSafeSQLString]; @@ -137,15 +140,16 @@ if (!sqlError) { sql - = [NSString stringWithFormat: @"UPDATE %@" - @" SET c_path = '/'||c_path1||'/'||c_path2||'/'||c_path3||'/'||c_path4" - @" WHERE c_path2 = '%@'", - [folderLocation gcsTableName], sqlToUserID]; + = [specialQueries updateCPathInFolderInfo: [folderLocation gcsTableName] + withCPath2: sqlToUserID]; sqlError = [fc evaluateExpressionX: sql]; } if (sqlError) - [ac rollbackTransaction]; + { + [ac rollbackTransaction]; + NSLog([sqlError reason]); + } else rc = [ac commitTransaction]; @@ -195,7 +199,10 @@ [profileLocation gcsTableName], sqlToUserID, sqlFromUserID]; sqlError = [fc evaluateExpressionX: sql]; if (sqlError) - [ac rollbackTransaction]; + { + [ac rollbackTransaction]; + NSLog([sqlError reason]); + } else rc = [ac commitTransaction];