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/SPDatabaseCopy.m | 59 +++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) (limited to 'Source/SPDatabaseCopy.m') diff --git a/Source/SPDatabaseCopy.m b/Source/SPDatabaseCopy.m index 913554c2..8942dee1 100644 --- a/Source/SPDatabaseCopy.m +++ b/Source/SPDatabaseCopy.m @@ -30,41 +30,44 @@ @synthesize dbInfo; -- (SPDatabaseInfo *)getDBInfoObject { +- (SPDatabaseInfo *)getDBInfoObject +{ if (dbInfo != nil) { return dbInfo; - } else { + } + else { dbInfo = [[SPDatabaseInfo alloc] init]; + [dbInfo setConnection:[self connection]]; [dbInfo setMessageWindow:messageWindow]; } + return dbInfo; } -- (BOOL)copyDatabaseFrom: (NSString *)sourceDatabaseName to: (NSString *)targetDatabaseName withContent:(BOOL)copyWithContent { - +- (BOOL)copyDatabaseFrom:(NSString *)sourceDatabaseName to:(NSString *)targetDatabaseName withContent:(BOOL)copyWithContent +{ SPDatabaseInfo *databaseInfo = [self getDBInfoObject]; - // check, whether the source database exists and the target database doesn't. + + // Check, whether the source database exists and the target database doesn't. NSArray *tables = [NSArray array]; + BOOL sourceExists = [databaseInfo databaseExists:sourceDatabaseName]; BOOL targetExists = [databaseInfo databaseExists:targetDatabaseName]; + if (sourceExists && !targetExists) { - // retrieve the list of tables/views/funcs/triggers from the source database - - tables = [connection listTablesFromDB:sourceDatabaseName]; - } else { - SPBeginAlertSheet(NSLocalizedString(@"Cannot create existing database", @"create database exists error message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to create the target database.\n\nDatabase %@ already exists.", - @"create database error informative message"), - targetDatabaseName]); + // Retrieve the list of tables/views/funcs/triggers from the source database + tables = [connection listTablesFromDB:sourceDatabaseName]; + } + else { return NO; } - DLog(@"list of found tables of source db: %@", tables); - + BOOL success = [self createDatabase:targetDatabaseName]; + SPTableCopy *dbActionTableCopy = [[SPTableCopy alloc] init]; + [dbActionTableCopy setConnection:connection]; for (NSString *currentTable in tables) { @@ -82,26 +85,20 @@ return success; } -- (BOOL) createDatabase: (NSString *)newDatabaseName { - NSString *createStatement = [NSString stringWithFormat:@"CREATE DATABASE %@", - [newDatabaseName backtickQuotedString]]; +- (BOOL)createDatabase:(NSString *)newDatabaseName +{ + NSString *createStatement = [NSString stringWithFormat:@"CREATE DATABASE %@", [newDatabaseName backtickQuotedString]]; + [connection queryString:createStatement]; - if ([connection queryErrored]) { - SPBeginAlertSheet(NSLocalizedString(@"Failed to create database", @"create database error message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to create the target database.\n\nMySQL said: %@", - @"create database error informative message"), - [connection getLastErrorMessage]]); - return NO; - } - return YES; - + if ([connection queryErrored]) return NO; + return YES; } -- (void)dealloc { - [dbInfo dealloc]; +- (void)dealloc +{ + [dbInfo release], dbInfo = nil; } -- cgit v1.2.3