diff options
author | drx777 <david.rekowski@gmx.de> | 2010-05-10 18:58:19 +0000 |
---|---|---|
committer | drx777 <david.rekowski@gmx.de> | 2010-05-10 18:58:19 +0000 |
commit | b4ad0ec8dc00e8fb5a575d425e7979af8615705c (patch) | |
tree | e2b346cd1e7e064f683d5891576ed8a333fe4d66 | |
parent | 95708b53e35b7dff1ae4b7b77f672ddc5d4fe293 (diff) | |
download | sequelpro-b4ad0ec8dc00e8fb5a575d425e7979af8615705c.tar.gz sequelpro-b4ad0ec8dc00e8fb5a575d425e7979af8615705c.tar.bz2 sequelpro-b4ad0ec8dc00e8fb5a575d425e7979af8615705c.zip |
- A database with views caused copy DB to crash. Thus, views are for the time being not copied, until handling them gets implemented. It is logged to the console for the users convenience.
- Only copy content if the table could be recreated successfully
- Corrected selector from [self getTableWindow] to messageWindow.
- Removed disabled code section
-rw-r--r-- | Source/SPTableCopy.m | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/Source/SPTableCopy.m b/Source/SPTableCopy.m index d868c9ad..5af46972 100644 --- a/Source/SPTableCopy.m +++ b/Source/SPTableCopy.m @@ -52,35 +52,28 @@ NSString *createTableResult = [self getCreateTableStatementFor:tableName inDB:sourceDB]; NSMutableString *createTableStatement = [[NSMutableString alloc] initWithString:createTableResult]; - // adding the target DB name and the separator dot after "CREATE TABLE ". - [createTableStatement insertString:@"." atIndex:13]; - [createTableStatement insertString:[targetDB backtickQuotedString] atIndex:13]; - /* - // this only works with MySQL >= 4.1 - NSString *copyStatement = [NSString stringWithFormat:@"CREATE TABLE %@.%@ LIKE %@.%@", - [targetDB backtickQuotedString], - [tableName backtickQuotedString], - [sourceDB backtickQuotedString], - [tableName backtickQuotedString] - ]; - DLog(@"Copying table %@ from %@ to %@", tableName, sourceDB, targetDB); - DLog(@"Copying table: %@", copyStatement); - [connection queryString:copyStatement]; - */ + if ([[createTableStatement substringToIndex:12] isEqualToString:@"CREATE TABLE"]) { + // adding the target DB name and the separator dot after "CREATE TABLE ". + [createTableStatement insertString:@"." atIndex:13]; + [createTableStatement insertString:[targetDB backtickQuotedString] atIndex:13]; - [connection queryString:createTableStatement]; - [createTableStatement release]; + [connection queryString:createTableStatement]; + [createTableStatement release]; - if ([connection queryErrored]) { - SPBeginAlertSheet(NSLocalizedString(@"Failed to copy table", @"copy table error message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to copy a table.\n\nMySQL said: %@", - @"copy table error informative message"), - [connection getLastErrorMessage]]); - return NO; + if ([connection queryErrored]) { + SPBeginAlertSheet(NSLocalizedString(@"Failed to copy table", @"copy table error message"), + NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to copy a table.\n\nMySQL said: %@", + @"copy table error informative message"), + [connection getLastErrorMessage]]); + return NO; + } + return YES; + } else { + NSLog(@"Could not copy non-table/view %@", tableName); } - return YES; + return NO; } - (BOOL)copyTable:(NSString *)tableName from: (NSString *)sourceDB to: (NSString *)targetDB withContent:(BOOL)copyWithContent{ @@ -88,7 +81,7 @@ BOOL structureCopyResult = [self copyTable:tableName from:sourceDB to:targetDB]; // optionally copy the table data using an insert select - if (copyWithContent == YES) { + if (structureCopyResult && copyWithContent) { NSString *copyDataStatement = [NSString stringWithFormat:@"INSERT INTO %@.%@ SELECT * FROM %@.%@", [targetDB backtickQuotedString], [tableName backtickQuotedString], @@ -99,7 +92,7 @@ if ([connection queryErrored]) { SPBeginAlertSheet(NSLocalizedString(@"Failed to copy table data", @"copy table data error message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, [self getTableWindow], self, nil, nil, + NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to copy a table's data.\n\nMySQL said: %@", @"copy table data error informative message"), [connection getLastErrorMessage]]); @@ -126,7 +119,7 @@ if ([connection queryErrored]) { SPBeginAlertSheet(NSLocalizedString(@"Failed to move table", @"move table error message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, [self getTableWindow], self, nil, nil, + NSLocalizedString(@"OK", @"OK button"), nil, nil, messageWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to move a table.\n\nMySQL said: %@", @"move table error informative message"), [connection getLastErrorMessage]]); |