aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseCopy.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/SPDatabaseCopy.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/SPDatabaseCopy.m')
-rw-r--r--Source/SPDatabaseCopy.m59
1 files changed, 28 insertions, 31 deletions
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;
}