From f1e829f98f50d9e75e7ba111361a625f7aab802d Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Fri, 13 Aug 2010 16:48:59 +0000 Subject: Tidy up database renaming and copying by removing the use of alert dialogs within loops to prevent locking up the main thread. These operations ideally should also be threaded. --- Source/SPDatabaseInfo.m | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'Source/SPDatabaseInfo.m') diff --git a/Source/SPDatabaseInfo.m b/Source/SPDatabaseInfo.m index 551a1c77..3c70aec9 100644 --- a/Source/SPDatabaseInfo.m +++ b/Source/SPDatabaseInfo.m @@ -27,42 +27,44 @@ @implementation SPDatabaseInfo --(BOOL)databaseExists:(NSString *)databaseName { +-(BOOL)databaseExists:(NSString *)databaseName +{ NSArray *names = [self listDBs]; + return [names containsObject:databaseName]; } -- (NSArray *)listDBs { +- (NSArray *)listDBs +{ return [self listDBsLike:nil]; } - (NSArray *)listDBsLike:(NSString *)dbsName { NSString *listDBStatement = nil; + if ((dbsName == nil) || ([dbsName isEqualToString:@""])) { listDBStatement = [NSString stringWithFormat:@"SHOW DATABASES"]; } else { listDBStatement = [NSString stringWithFormat:@"SHOW DATABASES LIKE %@", [dbsName backtickQuotedString]]; } - DLog(@"running query : %@", listDBStatement); + MCPResult *theResult = [connection queryString:listDBStatement]; - if ([connection queryErrored]) { - SPBeginAlertSheet(NSLocalizedString(@"Failed to retrieve databases list", @"database list error message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to retrieve a list of databases.\n\nMySQL said: %@", - @"database list error informative message"), - [connection getLastErrorMessage]]); - return NO; - } + if ([connection queryErrored]) return NO; NSMutableArray *names = [NSMutableArray array]; NSMutableString *name; + if ([theResult numOfRows] > 1) { - int i; - for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { + + NSUInteger i; + + for (i = 0 ; i < [theResult numOfRows]; i++) + { name = [[theResult fetchRowAsArray] objectAtIndex:0]; + [names addObject:name]; } } -- cgit v1.2.3