diff options
Diffstat (limited to 'Source/SPUserManager.m')
-rw-r--r-- | Source/SPUserManager.m | 56 |
1 files changed, 13 insertions, 43 deletions
diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index 83f0a12f..3b3add1e 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -29,6 +29,7 @@ #import "SPConnectionController.h" #import "SPServerSupport.h" #import "SPAlertSheets.h" +#import "SPMySQL.h" #import <BWToolkitFramework/BWAnchoredButtonBar.h> static const NSString *SPTableViewNameColumnID = @"NameColumn"; @@ -140,23 +141,11 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; NSMutableString *privKey; NSArray *privRow; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSMutableArray *resultAsArray = [NSMutableArray array]; NSMutableArray *usersResultArray = [NSMutableArray array]; // Select users from the mysql.user table - MCPResult *result = [self.mySqlConnection queryString:@"SELECT * FROM mysql.user ORDER BY user"]; - - NSUInteger rows = (NSUInteger)[result numOfRows]; - - if (rows > 0) [result dataSeek:0]; - - for (NSUInteger i = 0; i < rows; i++) - { - [resultAsArray addObject:[result fetchRowAsDictionary]]; - } - - [usersResultArray addObjectsFromArray:resultAsArray]; + SPMySQLResult *result = [self.mySqlConnection queryString:@"SELECT * FROM mysql.user ORDER BY user"]; + [usersResultArray addObjectsFromArray:[result getAllRows]]; [self _initializeTree:usersResultArray]; @@ -173,8 +162,8 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; [result setReturnDataAsStrings:YES]; } - if (result && [result numOfRows]) { - while ((privRow = [result fetchRowAsArray])) + if (result && [result numberOfRows]) { + while ((privRow = [result getRowAsArray])) { privKey = [NSMutableString stringWithString:[[privRow objectAtIndex:0] lowercaseString]]; @@ -193,7 +182,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; [result setReturnDataAsStrings:YES]; - while ((privRow = [result fetchRowAsArray])) + while ((privRow = [result getRowAsArray])) { privKey = [NSMutableString stringWithString:[privRow objectAtIndex:0]]; @@ -308,15 +297,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; { // Initialize Databases [schemas removeAllObjects]; - - MCPResult *results = [self.mySqlConnection listDBs]; - - if ([results numOfRows]) [results dataSeek:0]; - - for (NSUInteger i = 0; i < [results numOfRows]; i++) - { - [schemas addObject:[results fetchRowAsDictionary]]; - } + [schemas addObjectsFromArray:[self.mySqlConnection databases]]; [schemaController rearrangeObjects]; @@ -377,16 +358,10 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; NSString *queryString = [NSString stringWithFormat:@"SELECT * from mysql.db d WHERE d.user = %@ and d.host = %@", [[[child parent] valueForKey:@"user"] tickQuotedString], [[child valueForKey:@"host"] tickQuotedString]]; - MCPResult *queryResults = [self.mySqlConnection queryString:queryString]; + SPMySQLResult *queryResults = [self.mySqlConnection queryString:queryString]; - if ([queryResults numOfRows] > 0) { - // Go to the beginning - [queryResults dataSeek:0]; - } - - for (NSUInteger i = 0; i < [queryResults numOfRows]; i++) + for (NSDictionary *rowDict in queryResults) { - NSDictionary *rowDict = [queryResults fetchRowAsDictionary]; NSManagedObject *dbPriv = [NSEntityDescription insertNewObjectForEntityForName:@"Privileges" inManagedObjectContext:[self managedObjectContext]]; for (NSString *key in rowDict) @@ -1212,12 +1187,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; [[schemaPriv valueForKeyPath:@"user.host"] tickQuotedString], [dbName tickQuotedString]]; - MCPResult *result = [self.mySqlConnection queryString:statement]; - - NSUInteger rows = (NSUInteger)[result numOfRows]; - BOOL userExists = YES; - - if (rows == 0) userExists = NO; + NSArray *matchingUsers = [self.mySqlConnection getAllRowsFromQuery:statement]; for (NSString *key in self.privsSupportedByServer) { @@ -1228,7 +1198,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; [grantPrivileges addObject:[privilege replaceUnderscoreWithSpace]]; } else { - if (userExists || [grantPrivileges count] > 0) { + if ([matchingUsers count] || [grantPrivileges count] > 0) { [revokePrivileges addObject:[privilege replaceUnderscoreWithSpace]]; } } @@ -1433,11 +1403,11 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; { if ([self.mySqlConnection queryErrored]) { if (isSaving) { - [errorsString appendFormat:@"%@\n", [self.mySqlConnection getLastErrorMessage]]; + [errorsString appendFormat:@"%@\n", [self.mySqlConnection lastErrorMessage]]; } else { SPBeginAlertSheet(NSLocalizedString(@"An error occurred", @"mysql error occurred message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occurred whilst trying to perform the operation.\n\nMySQL said: %@", @"mysql error occurred informative message"), [self.mySqlConnection getLastErrorMessage]]); + [NSString stringWithFormat:NSLocalizedString(@"An error occurred whilst trying to perform the operation.\n\nMySQL said: %@", @"mysql error occurred informative message"), [self.mySqlConnection lastErrorMessage]]); } return NO; |