diff options
author | mltownsend <mltownsend@gmail.com> | 2009-10-29 23:40:09 +0000 |
---|---|---|
committer | mltownsend <mltownsend@gmail.com> | 2009-10-29 23:40:09 +0000 |
commit | 8287fc2305b38fdb3ecfa8ad5eef09cd745b80c9 (patch) | |
tree | 9051075a56709d0a63f96338e790a1907f54639f /Source | |
parent | c965c29b6ccf39a96a192f5c4bfffa2c0620cefc (diff) | |
download | sequelpro-8287fc2305b38fdb3ecfa8ad5eef09cd745b80c9.tar.gz sequelpro-8287fc2305b38fdb3ecfa8ad5eef09cd745b80c9.tar.bz2 sequelpro-8287fc2305b38fdb3ecfa8ad5eef09cd745b80c9.zip |
Got rid of a crash when using the User Manager and closing last Table Document. May be leaking now, not sure. Still needs some work.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPUserManager.h | 10 | ||||
-rw-r--r-- | Source/SPUserManager.m | 87 | ||||
-rw-r--r-- | Source/TableDocument.h | 5 | ||||
-rw-r--r-- | Source/TableDocument.m | 13 |
4 files changed, 53 insertions, 62 deletions
diff --git a/Source/SPUserManager.h b/Source/SPUserManager.h index 4af00c6c..4983ac49 100644 --- a/Source/SPUserManager.h +++ b/Source/SPUserManager.h @@ -44,13 +44,9 @@ } @property (nonatomic, retain) MCPConnection *mySqlConnection; - -- (NSPersistentStoreCoordinator *)persistentStoreCoordinator; -- (NSManagedObjectModel *)managedObjectModel; -- (NSManagedObjectContext *)managedObjectContext; - -- (id)initWithConnection:(MCPConnection *)connection; -- (void)initializeChild:(NSManagedObject *)child withItem:(NSDictionary *)item; +@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; +@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel; +@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext; // Add/Remove Users - (IBAction)addUser:(id)sender; diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index 40300dda..3978bec8 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -42,6 +42,7 @@ - (NSManagedObject *)_createNewSPUser; - (BOOL)checkAndDisplayMySqlError; - (void)_clearData; +- (void)initializeChild:(NSManagedObject *)child withItem:(NSDictionary *)item; @end @@ -49,31 +50,31 @@ @synthesize mySqlConnection; -/** - * Initialise the user manager with the supplied connection. - */ -- (id)initWithConnection:(MCPConnection*) connection +-(id)init { - if ((self = [super initWithWindowNibName:@"UserManagerView"])) { - - self.mySqlConnection = connection; - + if ((self = [super initWithWindowNibName:@"UserManagerView"])) + { // When reading privileges from the database, they are converted automatically to a // lowercase key used in the user privileges stores, from which a GRANT syntax // is derived automatically. While most keys can be automatically converted without // any difficulty, some keys differ slightly in mysql column storage to GRANT syntax; // this dictionary provides mappings for those values to ensure consistency. privColumnToGrantMap = [[NSDictionary alloc] initWithObjectsAndKeys: - @"Grant_option_priv", @"Grant_priv", - @"Show_databases_priv", @"Show_db_priv", - @"Create_temporary_tables_priv", @"Create_tmp_table_priv", - @"Replication_slave_priv", @"Repl_slave_priv", - @"Replication_client_priv", @"Repl_client_priv", - nil]; - - privsSupportedByServer = [[NSMutableDictionary alloc] init]; + @"Grant_option_priv", @"Grant_priv", + @"Show_databases_priv", @"Show_db_priv", + @"Create_temporary_tables_priv", @"Create_tmp_table_priv", + @"Replication_slave_priv", @"Repl_slave_priv", + @"Replication_client_priv", @"Repl_client_priv", + nil]; + + //privsSupportedByServer = [[NSMutableDictionary alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(contextDidSave:) + name:NSManagedObjectContextDidSaveNotification + object:nil]; + } - return self; } @@ -82,28 +83,22 @@ */ - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [managedObjectContext release], managedObjectContext = nil; - [persistentStoreCoordinator release], persistentStoreCoordinator = nil; - [managedObjectModel release], managedObjectModel = nil; - [privColumnToGrantMap release], privColumnToGrantMap = nil; - [privsSupportedByServer release], privsSupportedByServer = nil; - - [mySqlConnection release], mySqlConnection = nil; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:NSManagedObjectContextDidSaveNotification + object:nil]; + //[treeController release]; +// [managedObjectContext release]; +// [persistentStoreCoordinator release]; +// [managedObjectModel release]; + [privColumnToGrantMap release]; + [mySqlConnection release]; + //[privsSupportedByServer release]; [super dealloc]; } -/** - * Initialise various interface controls. - */ -- (void)awakeFromNib -{ - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(contextDidSave:) - name:NSManagedObjectContextDidSaveNotification - object:nil]; +-(void)windowDidLoad +{ [tabView selectTabViewItemAtIndex:0]; NSTableColumn *tableColumn = [outlineView tableColumnWithIdentifier:COLUMNIDNAME]; @@ -111,12 +106,17 @@ [imageAndTextCell setEditable:NO]; [tableColumn setDataCell:imageAndTextCell]; - + [self _initializeUsers]; + [super windowDidLoad]; } - (void)_initializeUsers { + /** + * This method reads in the users from the mysql.user table of the current + * connection. Then uses this information to initialize the NSOutlineView. + */ isInitializing = TRUE; NSMutableString *privKey; NSArray *privRow; @@ -125,6 +125,7 @@ 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`"] retain]; int rows = [result numOfRows]; if (rows > 0) @@ -177,13 +178,13 @@ for(int i = 0; i < [items count]; i++) { NSString *username = [[items objectAtIndex:i] objectForKey:@"User"]; - NSArray *array = [[self _fetchUserWithUserName:username] retain]; + NSArray *parentResults = [[self _fetchUserWithUserName:username] retain]; NSDictionary *item = [items objectAtIndex:i]; - if (array != nil && [array count] > 0) + if (parentResults != nil && [parentResults count] > 0) { // Add Children - NSManagedObject *parent = [array objectAtIndex:0]; + NSManagedObject *parent = [parentResults objectAtIndex:0]; NSManagedObject *child = [self _createNewSPUser]; [child setParent:parent]; [parent addChildrenObject:child]; @@ -209,7 +210,7 @@ { [[NSApplication sharedApplication] presentError:error]; } - [array release]; + [parentResults release]; } [outlineView reloadData]; } @@ -574,7 +575,7 @@ } droppedUsers = [[droppedUsers substringToIndex:[droppedUsers length]-2] mutableCopy]; [self.mySqlConnection queryString:[NSString stringWithFormat:@"DROP USER %@", droppedUsers]]; - + [droppedUsers release]; return TRUE; } @@ -681,8 +682,8 @@ - (NSManagedObject *)_createNewSPUser { - NSManagedObject *user = [[NSEntityDescription insertNewObjectForEntityForName:@"SPUser" - inManagedObjectContext:[self managedObjectContext]] autorelease]; + NSManagedObject *user = [NSEntityDescription insertNewObjectForEntityForName:@"SPUser" + inManagedObjectContext:[self managedObjectContext]]; return user; } diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 30d44084..414b7d4e 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -54,7 +54,9 @@ enum sp_current_query_mode IBOutlet id extendedTableInfoInstance; IBOutlet id databaseDataInstance; IBOutlet id spHistoryControllerInstance; - IBOutlet id exportControllerInstance; + IBOutlet id exportControllerInstance; + IBOutlet SPUserManager *userManagerInstance; + IBOutlet NSSearchField *listFilterField; @@ -119,7 +121,6 @@ enum sp_current_query_mode int passwordSheetReturnCode; SPConnectionController *connectionController; - SPUserManager *userManagerInstance; MCPConnection *mySQLConnection; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 9b00d82b..6cbccd60 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -260,7 +260,7 @@ NSData *pData = [NSData dataWithContentsOfFile:path options:NSUncachedRead error:&readError]; spf = [[NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] autorelease]; if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] @@ -484,7 +484,6 @@ [spfDocData setObject:[NSNumber numberWithBool:YES] forKey:@"auto_connect"]; [connectionController initiateConnection:self]; } - } /** @@ -640,11 +639,6 @@ [tableDataInstance setConnection:mySQLConnection]; [extendedTableInfoInstance setConnection:mySQLConnection]; [databaseDataInstance setConnection:mySQLConnection]; - - if (!userManagerInstance) { - userManagerInstance = [[SPUserManager alloc] initWithConnection:mySQLConnection]; - } - userManagerInstance.mySqlConnection = mySQLConnection; // Set the cutom query editor's MySQL version @@ -739,8 +733,7 @@ NSPrintPanel *printPanel = [op printPanel]; [printPanel setOptions:[printPanel options] + NSPrintPanelShowsOrientation + NSPrintPanelShowsScaling + NSPrintPanelShowsPaperSize]; - SPPrintAccessory *printAccessory = [[SPPrintAccessory alloc] init]; - [printAccessory initWithNibName:@"PrintAccessory" bundle:nil]; + SPPrintAccessory *printAccessory = [[SPPrintAccessory alloc] initWithNibName:@"PrintAccessory" bundle:nil]; [printAccessory setPrintView:printWebView]; [printPanel addAccessoryController:printAccessory]; @@ -2415,6 +2408,7 @@ format:NSPropertyListXMLFormat_v1_0 errorDescription:&err]; + [spf release]; if(err != nil) { NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting connection data", @"error while converting connection data")] defaultButton:NSLocalizedString(@"OK", @"OK button") @@ -3551,7 +3545,6 @@ if (taskDrawTimer) [taskDrawTimer release]; if(queryEditorInitString) [queryEditorInitString release]; if(spfSession) [spfSession release]; - if(userManagerInstance) [userManagerInstance release]; if(spfDocData) [spfDocData release]; if(keyChainID) [keyChainID release]; [super dealloc]; |