aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseRename.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-08-13 16:48:59 +0000
committerstuconnolly <stuart02@gmail.com>2010-08-13 16:48:59 +0000
commitf1e829f98f50d9e75e7ba111361a625f7aab802d (patch)
tree930c14091b0cba5d4c44ec1e4fc70c34f55c56fe /Source/SPDatabaseRename.m
parentefdcfb17f87863fef42f209f72eb4c4ccd888d35 (diff)
downloadsequelpro-f1e829f98f50d9e75e7ba111361a625f7aab802d.tar.gz
sequelpro-f1e829f98f50d9e75e7ba111361a625f7aab802d.tar.bz2
sequelpro-f1e829f98f50d9e75e7ba111361a625f7aab802d.zip
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.
Diffstat (limited to 'Source/SPDatabaseRename.m')
-rw-r--r--Source/SPDatabaseRename.m94
1 files changed, 41 insertions, 53 deletions
diff --git a/Source/SPDatabaseRename.m b/Source/SPDatabaseRename.m
index 33d01724..b565b406 100644
--- a/Source/SPDatabaseRename.m
+++ b/Source/SPDatabaseRename.m
@@ -30,97 +30,85 @@
@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)renameDatabaseFrom: (NSString *)sourceDatabaseName to: (NSString *)targetDatabaseName {
+- (BOOL)renameDatabaseFrom:(NSString *)sourceDatabaseName to:(NSString *)targetDatabaseName
+{
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
+ // 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]);
+ }
+ 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) {
- if ([dbActionTableCopy moveTable:currentTable
- from:sourceDatabaseName
- to:targetDatabaseName]) {
- } else {
- success = FALSE;
- }
+ for (NSString *currentTable in tables)
+ {
+ success = [dbActionTableCopy moveTable:currentTable from:sourceDatabaseName to:targetDatabaseName];
}
+
tables = [connection listTablesFromDB:sourceDatabaseName];
+
if ([tables count] == 0) {
[self dropDatabase:sourceDatabaseName];
- } else {
- SPBeginAlertSheet(NSLocalizedString(@"Failed to delete database", @"delete database error message"),
- NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"Database %@ not empty, skipping drop database.",
- @"delete database not empty error informative message"),
- sourceDatabaseName]);
- }
+ }
+
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 a database.\n\nMySQL said: %@",
- @"create database error informative message"),
- [connection getLastErrorMessage]]);
- return NO;
- }
- return YES;
+ if ([connection queryErrored]) return NO;
+
+ return YES;
}
-- (BOOL) dropDatabase: (NSString *)databaseName {
- NSString *dropStatement = [NSString stringWithFormat:@"DROP DATABASE %@",
- [databaseName backtickQuotedString]];
+- (BOOL)dropDatabase:(NSString *)databaseName
+{
+ NSString *dropStatement = [NSString stringWithFormat:@"DROP DATABASE %@", [databaseName backtickQuotedString]];
+
[connection queryString:dropStatement];
- if ([connection queryErrored]) {
- SPBeginAlertSheet(NSLocalizedString(@"Failed to drop database", @"drop database error message"),
- NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to drop a database.\n\nMySQL said: %@",
- @"drop 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;
}
@end \ No newline at end of file