Use GCSSpecialQueries in sogo-tool rename-user

Fixes #1924
The SQL syntax used by the former query would only work
with postgresql and Oracle.
pull/7/head
Jean Raby 2012-11-13 17:20:18 -05:00
parent 8c96f717c0
commit 378eef4082
2 changed files with 54 additions and 6 deletions

View File

@ -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

View File

@ -35,6 +35,7 @@
#import <GDLContentStore/GCSChannelManager.h>
#import <GDLContentStore/GCSFolder.h>
#import <GDLContentStore/GCSFolderManager.h>
#import <GDLContentStore/GCSSpecialQueries.h>
#import <GDLContentStore/NSURL+GCS.h>
#import <SOGo/NSString+Utilities.h>
@ -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];