/*
- Copyright (C) 2004-2005 SKYRIX Software AG
+ Copyright (C) 2004-2007 SKYRIX Software AG
This file is part of OpenGroupware.org.
sqlTest = [NSString stringWithFormat: sqlTestFormat,
potentialName, potentialName, potentialName];
count = 0;
- while ([[self performSQL: sqlTest] count] > 0) {
+ while ([[self performSQL: sqlTest] isNotEmpty]) {
count++;
potentialName = [NSString stringWithFormat: @"%@%d", _baseName, count];
sqlTest = [NSString stringWithFormat: sqlTestFormat,
}
- (NSException *)createFolderOfType:(NSString *)_type atPath:(NSString *)_path{
- GCSFolderType *ftype;
- NSString *tableName, *quickTableName, *aclTableName;
- NSString *baseURL;
+ // TBD: badly broken, needs to be wrapped in a transaction.
+ // TBD: would be best to perform all operations as a single SQL statement.
+ GCSFolderType *ftype;
+ NSString *tableName, *quickTableName, *aclTableName;
+ NSString *baseURL, *pathElement;
EOAdaptorChannel *channel;
- NSMutableArray *paths;
+ NSEnumerator *pathElements;
+ NSMutableArray *paths;
+ NSException *error;
+ NSString *sql;
if ([[self performSQL: [NSString stringWithFormat: @"SELECT * FROM %@"
@" WHERE c_path = '%@'",
[self folderInfoTableName], _path]]
- count] > 0) {
+ isNotEmpty]) {
return [NSException exceptionWithName:@"GCSExitingFolder"
reason:@"a folder already exists at that path"
userInfo:nil];
tableName = [self finalizedTableNameForBaseName: tableName
atBaseURL: baseURL withChannel: channel];
quickTableName = [NSString stringWithFormat: @"%@_quick", tableName];
- aclTableName = [NSString stringWithFormat: @"%@_acl", tableName];
-
- [channel evaluateExpressionX:
- [NSString stringWithFormat: @"DROP TABLE %@", tableName]];
- [channel evaluateExpressionX:
- [NSString stringWithFormat: @"DROP TABLE %@", quickTableName]];
- [channel evaluateExpressionX:
- [NSString stringWithFormat: @"DROP TABLE %@", aclTableName]];
- [channel evaluateExpressionX:
- [self sqlCreateWithTableName: tableName]];
- [channel evaluateExpressionX:
- [ftype sqlQuickCreateWithTableName: quickTableName]];
- [channel evaluateExpressionX:
- [self sqlAclCreateWithTableName: aclTableName]];
-
- paths = [NSMutableArray
- arrayWithArray: [_path componentsSeparatedByString: @"/"]];
+ aclTableName = [NSString stringWithFormat: @"%@_acl", tableName];
+
+ sql = [@"DROP TABLE " stringByAppendingString:tableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil)
+ return error;
+
+ sql = [@"DROP TABLE " stringByAppendingString:quickTableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil)
+ return error;
+
+ sql = [self sqlCreateWithTableName: tableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil)
+ return error;
+
+ sql = [ftype sqlQuickCreateWithTableName: quickTableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil)
+ return error;
+
+ sql = [@"DROP TABLE " stringByAppendingString:aclTableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil)
+ return error;
+
+ sql = [self sqlAclCreateWithTableName: aclTableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil)
+ return error;
+
+ paths = [[NSMutableArray alloc] initWithCapacity: 5];
+
+ pathElements = [[_path componentsSeparatedByString: @"/"] objectEnumerator];
+ while ((pathElement = [pathElements nextObject]) != nil) {
+ NSString *p = [[NSString alloc] initWithFormat: @"'%@'", pathElement];
+ [paths addObject: p];
+ [p release]; p = nil;
+ }
+
while ([paths count] < 5)
- [paths addObject: @""];
+ [paths addObject: @"NULL"];
- [channel evaluateExpressionX:
- [NSString stringWithFormat: @"INSERT INTO %@"
+ sql = [NSString stringWithFormat: @"INSERT INTO %@"
@" (c_path, c_path1, c_path2, c_path3, c_path4,"
@" c_foldername, c_location, c_quick_location,"
@" c_acl_location, c_folder_type)"
- @" VALUES ('%@', '%@', '%@', '%@', '%@', '%@', '%@/%@',"
+ @" VALUES ('%@', %@, %@, %@, %@, '%@', '%@/%@',"
@" '%@/%@', '%@/%@', '%@')",
[self folderInfoTableName], _path,
[paths objectAtIndex: 1], [paths objectAtIndex: 2],
baseURL, tableName,
baseURL, quickTableName,
baseURL, aclTableName,
- _type]];
+ _type];
+ if ((error = [channel evaluateExpressionX:sql]) != nil)
+ return error;
+ [paths release]; paths = nil;
[self releaseChannel: channel];
return nil;