From 05f1612cbb7e33cf9135a346fc2505cc0e87e853 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 23 Feb 2012 02:13:56 +0000 Subject: Warning: this branch commit is largely untested, and known to throw exceptions as database structure retrieval is currently missing! Further work on SPMySQLFramework integration: - Improve SPMySQL framework build settings including correct ppc builds and a Distribution configuration for the build distributions to match - Add new convenience querying and result methods to the framework - Amend Sequel Pro source to use the new SPMySQL.framework methods everywhere, replacing MCPKit methods where they differ and improving some functions - Remove MCPKit from the source - Fix a number of warnings on Release-style builds --- Source/SPUserManager.m | 56 ++++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 43 deletions(-) (limited to 'Source/SPUserManager.m') 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 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; -- cgit v1.2.3 From d4baea934555c1b58eba34db68712fdb67c7871f Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 15 Mar 2012 02:07:58 +0000 Subject: More SPMySQLIntegration bugfixes: - Return User Manager details as strings as some result types are marked as binary; fixes opening of user manager - User manager schema list is now a list of databases instead of a list of database dictionaries with one key; simplify model to match --- Source/SPUserManager.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/SPUserManager.m') diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index 3b3add1e..0e5f14cf 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -145,6 +145,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; // Select users from the mysql.user table SPMySQLResult *result = [self.mySqlConnection queryString:@"SELECT * FROM mysql.user ORDER BY user"]; + [result setReturnDataAsStrings:YES]; [usersResultArray addObjectsFromArray:[result getAllRows]]; [self _initializeTree:usersResultArray]; @@ -158,7 +159,6 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; if ([serverSupport supportsShowPrivileges]) { result = [self.mySqlConnection queryString:@"SHOW PRIVILEGES"]; - [result setReturnDataAsStrings:YES]; } @@ -178,8 +178,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; } // If that fails, base privilege support on the mysql.users columns else { - result = [self.mySqlConnection queryString:@"SHOW COLUMNS FROM mysql.user"]; - + result = [self.mySqlConnection queryString:@"SHOW COLUMNS FROM mysql.user"]; [result setReturnDataAsStrings:YES]; while ((privRow = [result getRowAsArray])) @@ -359,6 +358,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; [[[child parent] valueForKey:@"user"] tickQuotedString], [[child valueForKey:@"host"] tickQuotedString]]; SPMySQLResult *queryResults = [self.mySqlConnection queryString:queryString]; + [queryResults setReturnDataAsStrings:YES]; for (NSDictionary *rowDict in queryResults) { @@ -856,7 +856,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; // The passed in objects should be an array of NSDictionaries with a key // of "name". NSManagedObject *selectedHost = [[treeController selectedObjects] objectAtIndex:0]; - NSString *selectedDb = [[[schemaController selectedObjects] objectAtIndex:0] valueForKey:@"Database"]; + NSString *selectedDb = [[schemaController selectedObjects] objectAtIndex:0]; NSArray *selectedPrivs = [self _fetchPrivsWithUser:[selectedHost valueForKeyPath:@"parent.user"] schema:[selectedDb stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"] host:[selectedHost valueForKey:@"host"]]; @@ -1535,7 +1535,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; // Check to see if the user host node was selected if ([user valueForKey:@"host"]) { - NSString *selectedSchema = [[[schemaController selectedObjects] objectAtIndex:0] valueForKey:@"Database"]; + NSString *selectedSchema = [[schemaController selectedObjects] objectAtIndex:0]; NSArray *results = [self _fetchPrivsWithUser:[[user parent] valueForKey:@"user"] schema:[selectedSchema stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"] host:[user valueForKey:@"host"]]; -- cgit v1.2.3