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/SPDatabaseDocument.m | 201 +++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 103 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 53d9b5c6..fef580ba 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -35,6 +35,8 @@ enum { #import "SPDatabaseDocument.h" #import "SPConnectionController.h" +#import "SPMySQL.h" + #import "SPTablesList.h" #import "SPTableStructure.h" #ifndef SP_REFACTOR /* headers */ @@ -393,7 +395,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #pragma mark - #pragma mark Connection callback and methods -- (void)setConnection:(MCPConnection *)theConnection +- (void)setConnection:(SPMySQLConnection *)theConnection { _isConnected = YES; mySQLConnection = [theConnection retain]; @@ -570,7 +572,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; * * @return The document's connection */ -- (MCPConnection *) getConnection +- (SPMySQLConnection *) getConnection { return mySQLConnection; } @@ -604,28 +606,22 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [[chooseDatabaseButton menu] addItem:[NSMenuItem separatorItem]]; #endif - MCPResult *queryResult = [mySQLConnection listDBs]; - - if ([queryResult numOfRows]) [queryResult dataSeek:0]; - if (allDatabases) [allDatabases release]; if (allSystemDatabases) [allSystemDatabases release]; - allDatabases = [[NSMutableArray alloc] initWithCapacity:(NSUInteger)[queryResult numOfRows]]; + NSArray *theDatabaseList = [mySQLConnection databases]; + allDatabases = [[NSMutableArray alloc] initWithCapacity:[theDatabaseList count]]; allSystemDatabases = [[NSMutableArray alloc] initWithCapacity:2]; - for (NSUInteger i = 0 ; i < [queryResult numOfRows] ; i++) - { - NSString *database = NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0); + for (NSString *databaseName in theDatabaseList) { - // If the database is either information_schema or mysql then it is classed as a system table - // 5.5.3+ performance_schema - if ([database isEqualToString:@"information_schema"] || [database isEqualToString:@"mysql"] || [database isEqualToString:@"performance_schema"]) { - [allSystemDatabases addObject:database]; - } - else { - [allDatabases addObject:database]; + // If the database is either information_schema or mysql then it is classed as a + // system table; similarly, for 5.5.3+, performance_schema + if ([databaseName isEqualToString:@"information_schema"] || [databaseName isEqualToString:@"mysql"] || [databaseName isEqualToString:@"performance_schema"]) { + [allSystemDatabases addObject:databaseName]; + } else { + [allDatabases addObject:databaseName]; } } @@ -984,15 +980,13 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self]; #endif - MCPResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"]; + SPMySQLResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"]; + [theResult setDefaultRowReturnType:SPMySQLResultRowAsArray]; if (![mySQLConnection queryErrored]) { - NSInteger i; - NSInteger r = (NSInteger)[theResult numOfRows]; - if (r) [theResult dataSeek:0]; - for ( i = 0 ; i < r ; i++ ) { - dbName = NSArrayObjectAtIndex([theResult fetchRowAsArray], 0); + for (NSArray *eachRow in theResult) { + dbName = NSArrayObjectAtIndex(eachRow, 0); } - if(![dbName isKindOfClass:[NSNull class]]) { + if(![dbName isNSNull]) { if(![dbName isEqualToString:selectedDatabase]) { if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; selectedDatabase = [[NSString alloc] initWithString:dbName]; @@ -1557,7 +1551,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; */ - (void)detectDatabaseEncoding { - MCPResult *charSetResult; + SPMySQLResult *charSetResult; NSString *mysqlEncoding = nil; _supportsEncoding = YES; @@ -1566,11 +1560,11 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if ([serverSupport supportsCharacterSetDatabaseVar]) { charSetResult = [mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set_database'"]; [charSetResult setReturnDataAsStrings:YES]; - mysqlEncoding = [[charSetResult fetchRowAsDictionary] objectForKey:@"Value"]; + mysqlEncoding = [[charSetResult getRowAsDictionary] objectForKey:@"Value"]; } // MySQL 4.0 or older -> only default character set possible, cannot choose others using "set names xy" else { - mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] fetchRowAsDictionary] objectForKey:@"Value"]; + mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] getRowAsDictionary] objectForKey:@"Value"]; } [selectedDatabaseEncoding release]; @@ -1656,13 +1650,13 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - MCPResult *theResult = [mySQLConnection queryString:query]; + SPMySQLResult *theResult = [mySQLConnection queryString:query]; [theResult setReturnDataAsStrings:YES]; // Check for errors, only displaying if the connection hasn't been terminated if ([mySQLConnection queryErrored]) { if ([mySQLConnection isConnected]) { - NSRunAlertPanel(@"Error", [NSString stringWithFormat:NSLocalizedString(@"An error occured while creating table syntax.\n\n: %@", @"Error shown when unable to show create table syntax"),[mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + NSRunAlertPanel(@"Error", [NSString stringWithFormat:NSLocalizedString(@"An error occured while creating table syntax.\n\n: %@", @"Error shown when unable to show create table syntax"), [mySQLConnection lastErrorMessage]], @"OK", nil, nil); } return; @@ -1670,9 +1664,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; NSString *tableSyntax; if (type == SPTableTypeProc) - tableSyntax = [NSString stringWithFormat:@"DELIMITER ;;\n%@;;\nDELIMITER ", [[theResult fetchRowAsArray] objectAtIndex:colOffs]]; + tableSyntax = [NSString stringWithFormat:@"DELIMITER ;;\n%@;;\nDELIMITER ", [[theResult getRowAsArray] objectAtIndex:colOffs]]; else - tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs]; + tableSyntax = [[theResult getRowAsArray] objectAtIndex:colOffs]; // A NULL value indicates that the user does not have permission to view the syntax if ([tableSyntax isNSNull]) { @@ -1755,7 +1749,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -1768,7 +1762,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to check the %@.\n\nMySQL said:%@",@"an error occurred while trying to check the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to check the %@.\n\nMySQL said:%@",@"an error occurred while trying to check the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -1778,10 +1772,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in theResult) { + if (![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } @@ -1789,7 +1783,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Process result if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Check table successfully passed.",@"check table successfully passed message") : NSLocalizedString(@"Check table failed.", @"check table failed message"); @@ -1811,7 +1805,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while checking selected items", @"error while checking selected items message")]; @@ -1831,7 +1825,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -1844,7 +1838,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while analyzing the %@.\n\nMySQL said:%@",@"an error occurred while analyzing the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while analyzing the %@.\n\nMySQL said:%@",@"an error occurred while analyzing the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -1854,18 +1848,18 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in resultStatuses) { + if(![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } } // Process result - if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if ([selectedItems count] == 1) { + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully analyzed table.",@"analyze table successfully passed message") : NSLocalizedString(@"Analyze table failed.", @"analyze table failed message"); @@ -1887,7 +1881,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while analyzing selected items", @"error while analyzing selected items message")]; @@ -1907,7 +1901,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -1920,7 +1914,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while optimzing the %@.\n\nMySQL said:%@",@"an error occurred while trying to optimze the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while optimzing the %@.\n\nMySQL said:%@",@"an error occurred while trying to optimze the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -1930,18 +1924,18 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in resultStatuses) { + if (![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } } // Process result - if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if ([selectedItems count] == 1) { + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully optimized table.",@"optimize table successfully passed message") : NSLocalizedString(@"Optimize table failed.", @"optimize table failed message"); @@ -1963,7 +1957,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while optimizing selected items", @"error while optimizing selected items message")]; @@ -1982,7 +1976,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -1995,7 +1989,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while repairing the %@.\n\nMySQL said:%@",@"an error occurred while trying to repair the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while repairing the %@.\n\nMySQL said:%@",@"an error occurred while trying to repair the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -2005,18 +1999,18 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in resultStatuses) { + if (![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } } // Process result - if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if ([selectedItems count] == 1) { + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully repaired table.",@"repair table successfully passed message") : NSLocalizedString(@"Repair table failed.", @"repair table failed message"); @@ -2025,7 +2019,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; message = NSLocalizedString(@"Successfully repaired all selected items.",@"successfully repaired all selected items message"); } - if(message) { + if (message) { [[NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Repair %@", @"REPAIR one or more tables - result title"), what] defaultButton:@"OK" alternateButton:nil @@ -2038,7 +2032,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while repairing selected items", @"error while repairing selected items message")]; @@ -2057,7 +2051,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"FLUSH TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"FLUSH TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -2070,7 +2064,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while flushing the %@.\n\nMySQL said:%@",@"an error occurred while trying to flush the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while flushing the %@.\n\nMySQL said:%@",@"an error occurred while trying to flush the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -2080,18 +2074,18 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in resultStatuses) { + if (![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } } // Process result - if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if ([selectedItems count] == 1) { + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully flushed table.",@"flush table successfully passed message") : NSLocalizedString(@"Flush table failed.", @"flush table failed message"); @@ -2100,7 +2094,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; message = NSLocalizedString(@"Successfully flushed all selected items.",@"successfully flushed all selected items message"); } - if(message) { + if (message) { [[NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Flush %@", @"FLUSH one or more tables - result title"), what] defaultButton:@"OK" alternateButton:nil @@ -2113,7 +2107,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while flushing selected items", @"error while flushing selected items message")]; @@ -2132,7 +2126,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -2144,7 +2138,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while performing the checksum on %@.\n\nMySQL said:%@",@"an error occurred while performing the checksum on the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while performing the checksum on %@.\n\nMySQL said:%@",@"an error occurred while performing the checksum on the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -2155,8 +2149,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } // Process result - if([selectedItems count] == 1) { - message = [[[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject] objectForKey:@"Checksum"]; + NSArray *resultStatuses = [theResult getAllRows]; + if ([selectedItems count] == 1) { + message = [[resultStatuses lastObject] objectForKey:@"Checksum"]; [[NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Checksum %@",@"checksum %@ message"), what] defaultButton:@"OK" alternateButton:nil @@ -2167,9 +2162,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; didEndSelector:NULL contextInfo:NULL]; } else { - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Checksums of %@",@"Checksums of %@ message"), what]]; [alert setMessageText:NSLocalizedString(@"Table checksum",@"table checksum message")]; @@ -2297,9 +2291,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } // Before displaying the user manager make sure the current user has access to the mysql.user table. - MCPResult *result = [mySQLConnection queryString:@"SELECT * FROM `mysql`.`user` ORDER BY `user`"]; + SPMySQLResult *result = [mySQLConnection queryString:@"SELECT * FROM `mysql`.`user` ORDER BY `user`"]; - if ([mySQLConnection queryErrored] && ([result numOfRows] == 0)) { + if ([mySQLConnection queryErrored] && ([result numberOfRows] == 0)) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Unable to get list of users", @"unable to get list of users message") defaultButton:NSLocalizedString(@"OK", @"OK button") @@ -2357,7 +2351,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; SPBeginAlertSheet(NSLocalizedString(@"Flushed Privileges", @"title of panel when successfully flushed privs"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, NSLocalizedString(@"Successfully flushed privileges.", @"message of panel when successfully flushed privs")); } else { //error while flushing privileges - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't flush privileges.\nMySQL said: %@", @"message of panel when flushing privs failed"), [mySQLConnection getLastErrorMessage]]); + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't flush privileges.\nMySQL said: %@", @"message of panel when flushing privs failed"), [mySQLConnection lastErrorMessage]]); } } @@ -5088,7 +5082,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } // Get create syntax - MCPResult *queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE %@ %@", + SPMySQLResult *queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE %@ %@", itemTypeStr, [item backtickQuotedString] ]]; @@ -5096,15 +5090,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if (changeEncoding) [mySQLConnection restoreStoredEncoding]; - if ( ![queryResult numOfRows] ) { + if ( ![queryResult numberOfRows] ) { //error while getting table structure SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"Couldn't get create syntax.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection getLastErrorMessage]]); + [NSString stringWithFormat:NSLocalizedString(@"Couldn't get create syntax.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection lastErrorMessage]]); status = @"1"; } else { - NSString *syntaxString = [[queryResult fetchRowAsArray] objectAtIndex:queryCol]; + NSString *syntaxString = [[queryResult getRowAsArray] objectAtIndex:queryCol]; // A NULL value indicates that the user does not have permission to view the syntax if ([syntaxString isNSNull]) { @@ -5179,21 +5173,21 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; SPFileHandle *fh = [SPFileHandle fileHandleForWritingAtPath:resultFileName]; if(!fh) NSLog(@"Couldn't create file handle to %@", resultFileName); - MCPStreamingResult *theResult = [mySQLConnection streamingQueryString:query]; + SPMySQLResult *theResult = [mySQLConnection streamingQueryString:query]; [theResult setReturnDataAsStrings:YES]; if ([mySQLConnection queryErrored]) { - [fh writeData:[[NSString stringWithFormat:@"MySQL said: %@", [mySQLConnection getLastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]]; + [fh writeData:[[NSString stringWithFormat:@"MySQL said: %@", [mySQLConnection lastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]]; status = @"1"; } else { // write header if(writeAsCsv) - [fh writeData:[[[theResult fetchFieldNames] componentsJoinedAsCSV] dataUsingEncoding:NSUTF8StringEncoding]]; + [fh writeData:[[[theResult fieldNames] componentsJoinedAsCSV] dataUsingEncoding:NSUTF8StringEncoding]]; else - [fh writeData:[[[theResult fetchFieldNames] componentsJoinedByString:@"\t"] dataUsingEncoding:NSUTF8StringEncoding]]; + [fh writeData:[[[theResult fieldNames] componentsJoinedByString:@"\t"] dataUsingEncoding:NSUTF8StringEncoding]]; [fh writeData:[[NSString stringWithString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding]]; - NSArray *columnDefinition = [theResult fetchResultFieldsStructure]; + NSArray *columnDefinition = [theResult fieldDefinitions]; // Write table meta data NSMutableString *tableMetaData = [NSMutableString string]; @@ -5221,10 +5215,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; NSUInteger i, j; NSArray *theRow; NSMutableString *result = [NSMutableString string]; - if(writeAsCsv) { - for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { + if (writeAsCsv) { + for ( i = 0 ; i < [theResult numberOfRows] ; i++ ) { [result setString:@""]; - theRow = [theResult fetchNextRowAsArray]; + theRow = [theResult getRowAsArray]; for( j = 0 ; j < [theRow count] ; j++ ) { NSEvent* event = [NSApp currentEvent]; @@ -5238,9 +5232,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([result length]) [result appendString:@","]; id cell = NSArrayObjectAtIndex(theRow, j); - if([cell isKindOfClass:[NSNull class]]) + if([cell isNSNull]) [result appendString:@"\"NULL\""]; - else if([cell isKindOfClass:[MCPGeometryData class]]) + else if([cell isKindOfClass:[SPMySQLGeometryData class]]) [result appendFormat:@"\"%@\"", [cell wktString]]; else if([cell isKindOfClass:[NSData class]]) { NSString *displayString = [[NSString alloc] initWithData:cell encoding:[mySQLConnection stringEncoding]]; @@ -5261,9 +5255,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } } else { - for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { + for ( i = 0 ; i < [theResult numberOfRows] ; i++ ) { [result setString:@""]; - theRow = [theResult fetchNextRowAsArray]; + theRow = [theResult getRowAsArray]; for( j = 0 ; j < [theRow count] ; j++ ) { NSEvent* event = [NSApp currentEvent]; @@ -5277,9 +5271,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([result length]) [result appendString:@"\t"]; id cell = NSArrayObjectAtIndex(theRow, j); - if([cell isKindOfClass:[NSNull class]]) + if([cell isNSNull]) [result appendString:@"NULL"]; - else if([cell isKindOfClass:[MCPGeometryData class]]) + else if([cell isKindOfClass:[SPMySQLGeometryData class]]) [result appendFormat:@"%@", [cell wktString]]; else if([cell isKindOfClass:[NSData class]]) { NSString *displayString = [[NSString alloc] initWithData:cell encoding:[mySQLConnection stringEncoding]]; @@ -5817,13 +5811,13 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if ([mySQLConnection queryErrored]) { // An error occurred - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't create database.\nMySQL said: %@", @"message of panel when creation of db failed"), [mySQLConnection getLastErrorMessage]]); + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't create database.\nMySQL said: %@", @"message of panel when creation of db failed"), [mySQLConnection lastErrorMessage]]); return; } // Error while selecting the new database (is this even possible?) - if (![mySQLConnection selectDB:[databaseNameField stringValue]] ) { + if (![mySQLConnection selectDatabase:[databaseNameField stringValue]] ) { SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to database %@.\nBe sure that you have the necessary privileges.", @"message of panel when connection to db failed after selecting from popupbutton"), [databaseNameField stringValue]]); [self setDatabases:self]; @@ -5871,7 +5865,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [self performSelector:@selector(showErrorSheetWith:) withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"), [NSString stringWithFormat:NSLocalizedString(@"Couldn't delete the database.\nMySQL said: %@", @"message of panel when deleting db failed"), - [mySQLConnection getLastErrorMessage]], + [mySQLConnection lastErrorMessage]], nil] afterDelay:0.3]; @@ -5882,6 +5876,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // do to threading we have to delete it from 'allDatabases' directly // before calling navigator [allDatabases removeObject:[self database]]; + // This only deletes the db and refreshes the navigator since nothing is changed // that's why we can run this on main thread [mySQLConnection queryDbStructureWithUserInfo:nil]; @@ -5935,7 +5930,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Attempt to select the specified database, and abort on failure #ifndef SP_REFACTOR /* patch */ if ([chooseDatabaseButton indexOfItemWithTitle:targetDatabaseName] == NSNotFound - || ![mySQLConnection selectDB:targetDatabaseName]) + || ![mySQLConnection selectDatabase:targetDatabaseName]) #else if ( ![mySQLConnection selectDB:targetDatabaseName] ) #endif -- cgit v1.2.3 From 79eff5bf42154da8d7730e0e0159160f68ec4e16 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 14 Mar 2012 01:16:18 +0000 Subject: =?UTF-8?q?Final=20feature=20work=20on=20the=20SPMySQL=20branch=20?= =?UTF-8?q?before=20merging:=20=20-=20Add=20a=20ping=20keepalive=20managin?= =?UTF-8?q?g=20object=20to=20prevent=20retain=20cycles=20from=20the=20NSTi?= =?UTF-8?q?mer=20=20-=20Add=20-[SPMySQLConnection=20copy]=20support=20=20-?= =?UTF-8?q?=20Refactor=20Hans-J=C3=B6rg=20Bibiko's=20database=20structure?= =?UTF-8?q?=20retrieval,=20moving=20it=20out=20of=20the=20MySQL=20framewor?= =?UTF-8?q?k=20and=20building=20it=20around=20a=20copy=20of=20the=20connec?= =?UTF-8?q?tion.=20=20This=20reduces=20the=20amount=20of=20connections-ove?= =?UTF-8?q?r-time=20used=20by=20Sequel=20Pro=20to=20two=20constant=20conne?= =?UTF-8?q?ctions=20(addressing=20Issue=20#1097)=20and=20improves=20robust?= =?UTF-8?q?ness.=20=20-=20Use=20the=20database=20structure=20retrieval=20c?= =?UTF-8?q?onnection=20for=20faster=20query=20cancellation=20without=20an?= =?UTF-8?q?=20extra=20connection=20required,=20if=20possible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPDatabaseDocument.m | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index fef580ba..c8154c7f 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -60,6 +60,7 @@ enum { #import "SPTableData.h" #endif #import "SPDatabaseData.h" +#import "SPDatabaseStructure.h" #ifndef SP_REFACTOR /* headers */ #import "SPAppController.h" #import "SPExtendedTableInfo.h" @@ -119,6 +120,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif @synthesize isProcessing; @synthesize serverSupport; +@synthesize databaseStructureRetrieval; #ifndef SP_REFACTOR /* ivars */ @synthesize processID; #endif @@ -218,6 +220,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [nibLoader release]; [nibObjectsToRelease addObjectsFromArray:dbViewTopLevelObjects]; #endif + + databaseStructureRetrieval = [[SPDatabaseStructure alloc] initWithDelegate:self]; } return self; @@ -434,6 +438,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [chooseDatabaseButton setEnabled:!_isWorkingLevel]; + // Set the connection on the database structure builder + [databaseStructureRetrieval setConnectionToClone:mySQLConnection]; + [databaseDataInstance setConnection:mySQLConnection]; // Pass the support class to the data instance @@ -1357,7 +1364,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if (!taskCanBeCancelled) return; [taskCancelButton setEnabled:NO]; - [mySQLConnection cancelCurrentQuery]; + + // See whether there is an active database structure task and whether it can be used + // to cancel the query, for speed (no connection overhead!) + if (databaseStructureRetrieval && [databaseStructureRetrieval connection]) { + [mySQLConnection setLastQueryWasCancelled:YES]; + [[databaseStructureRetrieval connection] killQueryOnThreadID:[mySQLConnection mysqlConnectionThreadId]]; + } else { + [mySQLConnection cancelCurrentQuery]; + } if (taskCancellationCallbackObject && taskCancellationCallbackSelector) { [taskCancellationCallbackObject performSelector:taskCancellationCallbackSelector]; @@ -5658,6 +5673,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif + [databaseStructureRetrieval release]; + [allDatabases release]; [allSystemDatabases release]; #ifndef SP_REFACTOR /* dealloc ivars */ @@ -5879,7 +5896,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // This only deletes the db and refreshes the navigator since nothing is changed // that's why we can run this on main thread - [mySQLConnection queryDbStructureWithUserInfo:nil]; + [databaseStructureRetrieval queryDbStructureWithUserInfo:nil]; // Delete was successful if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; -- cgit v1.2.3 From 76a070a62a076481dddfb5e5a7d8ca6de5ea64a4 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 14 Mar 2012 22:07:03 +0000 Subject: More bugfixes to the SPMySQL integration branch: - Fix background database structure checks throwing exceptions at the end of certain table operations - Fix incorrect timer access/overrelease when closing a SPNarrowDownCompletion window when database structure fetching is active --- Source/SPDatabaseDocument.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index c8154c7f..ac6d4dda 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -929,7 +929,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [self _addDatabase]; // Query the structure of all databases in the background (mainly for completion) - [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]]; + [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:databaseStructureRetrieval withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]]; } else { // reset chooseDatabaseButton -- cgit v1.2.3