From 4b071f5866460dbff1bce10a297f3b017dfea26b Mon Sep 17 00:00:00 2001 From: dmoagx Date: Wed, 6 Jul 2011 18:47:44 +0000 Subject: * Fixes a spacing issue in Duplicate DB Sheet * Fixes a case were for string == NULL was checked instead of [string length] == 0 (fixes #1103) * Fixes a logic error while copying databases and adds ability to copy InnoDB tables with foreign key checks (fixes #1111) --- Interfaces/English.lproj/DBView.xib | 21 ++++++++++++++++++--- Source/SPDatabaseCopy.m | 14 ++++---------- Source/SPExportController.m | 2 +- Source/SPTableCopy.h | 15 +++++++++++++++ Source/SPTableCopy.m | 36 +++++++++++++++++++++++++++++------- 5 files changed, 67 insertions(+), 21 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 7f7fe455..0b8ee626 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -6664,7 +6664,7 @@ {292, 132} {292, 132} - + 256 YES @@ -6673,6 +6673,7 @@ 256 {{17, 98}, {258, 14}} + YES 68288064 @@ -6689,6 +6690,7 @@ 258 {{20, 72}, {252, 18}} + YES -1804468671 @@ -6704,8 +6706,9 @@ 259 - {{204, 13}, {77, 28}} + {{176, 13}, {101, 28}} + 1 YES @@ -6727,8 +6730,9 @@ 259 - {{136, 13}, {70, 28}} + {{85, 13}, {93, 28}} + YES 67239424 @@ -6750,6 +6754,7 @@ 268 {{18, 48}, {256, 18}} + YES 67239424 @@ -6769,6 +6774,8 @@ {292, 132} + + {{0, 0}, {1280, 778}} {292, 154} @@ -24296,12 +24303,14 @@ bGQgTmFtZQkgID0gQAoJCQkJICBMRU5HVEgoYEBgKSA+IEA 6938.IBPluginDependency 6938.ImportedFromIB2 6939.IBPluginDependency + 6939.IBViewBoundsToFrameTransform 6939.ImportedFromIB2 6942.IBPluginDependency 6942.ImportedFromIB2 6943.IBPluginDependency 6943.ImportedFromIB2 6944.IBPluginDependency + 6944.IBViewBoundsToFrameTransform 6944.ImportedFromIB2 6945.IBPluginDependency 6946.IBPluginDependency @@ -26015,12 +26024,18 @@ bGQgTmFtZQkgID0gQAoJCQkJICBMRU5HVEgoYEBgKSA+IEA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABDRwAAwhwAAA + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABCngAAwhwAAA + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin diff --git a/Source/SPDatabaseCopy.m b/Source/SPDatabaseCopy.m index 66b6ba1b..c2371f3d 100644 --- a/Source/SPDatabaseCopy.m +++ b/Source/SPDatabaseCopy.m @@ -64,21 +64,15 @@ return NO; } - BOOL success = [self createDatabase:targetDatabaseName]; + //abort here if database creation failed + if(![self createDatabase:targetDatabaseName]) + return NO; SPTableCopy *dbActionTableCopy = [[SPTableCopy alloc] init]; [dbActionTableCopy setConnection:connection]; - for (NSString *currentTable in tables) { - if ([dbActionTableCopy copyTable:currentTable - from:sourceDatabaseName - to:targetDatabaseName - withContent:copyWithContent]) { - } else { - success = NO; - } - } + BOOL success = [dbActionTableCopy copyTables:tables from:sourceDatabaseName to:targetDatabaseName withContent:copyWithContent]; [dbActionTableCopy release]; diff --git a/Source/SPExportController.m b/Source/SPExportController.m index 0ff78c1f..b22d2c32 100644 --- a/Source/SPExportController.m +++ b/Source/SPExportController.m @@ -639,7 +639,7 @@ static const NSString *SPSQLExportDropEnabled = @"SQLExportDropEnabled"; // Check whether to save the export filename. Save it if it's not blank and contains at least one // token - this suggests it's not a one-off filename - if (![exportCustomFilenameTokenField stringValue]) { + if ([[exportCustomFilenameTokenField stringValue] length] < 1) { [prefs removeObjectForKey:SPExportFilenameFormat]; } else { BOOL saveFilename = NO; diff --git a/Source/SPTableCopy.h b/Source/SPTableCopy.h index 32eadcfc..56e1da8c 100644 --- a/Source/SPTableCopy.h +++ b/Source/SPTableCopy.h @@ -35,6 +35,7 @@ * @param name name of the table in the source database * @param sourceDB name of the source database * @param targetDB name of the target database + * @return YES on success, NO on any kind of error (unspecified) */ - (BOOL)copyTable:(NSString *)name from: (NSString *)sourceDB to: (NSString *)targetDB; @@ -54,7 +55,21 @@ * @param sourceDB name of the source database * @param targetDB name of the target database * @param copyWithContent whether to copy the content too, otherwise only structure + * @return YES on success, NO on any kind of error (unspecified) */ - (BOOL)copyTable:(NSString *)tableName from: (NSString *)sourceDB to: (NSString *)targetDB withContent:(BOOL)copyWithContent; +/** + * This method copies a bunch of tables including their data from one db to another. + * + * @param tableArray array of NSStrings with the table names in the sourceDB + * @param sourceDB name of the source database + * @param targetDB name of the target database + * @param copyWithContent whether to copy the content too, otherwise only structure + * @return YES on success, NO on any kind of error (unspecified) + * + * This method is able to copy InnoDB tables with foreign key constraints. + */ +- (BOOL)copyTables:(NSArray *)tablesArray from:(NSString *)sourceDB to:(NSString *)targetDB withContent:(BOOL)copyWithContent; + @end diff --git a/Source/SPTableCopy.m b/Source/SPTableCopy.m index d390243c..5aa55df1 100644 --- a/Source/SPTableCopy.m +++ b/Source/SPTableCopy.m @@ -55,7 +55,7 @@ [createTableStatement release]; - return [connection queryErrored]; + return ![connection queryErrored]; } [createTableStatement release]; @@ -66,10 +66,10 @@ - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB withContent:(BOOL)copyWithContent { // Copy the table structure - BOOL structureCopyResult = [self copyTable:tableName from:sourceDB to:targetDB]; + BOOL structureCopySuccess = [self copyTable:tableName from:sourceDB to:targetDB]; // Optionally copy the table data using an insert select - if (structureCopyResult && structureCopyResult && copyWithContent) { + if (structureCopySuccess && copyWithContent) { NSString *copyDataStatement = [NSString stringWithFormat:@"INSERT INTO %@.%@ SELECT * FROM %@.%@", [targetDB backtickQuotedString], @@ -80,12 +80,34 @@ [connection queryString:copyDataStatement]; - if ([connection queryErrored]) return NO; - - return YES; + return ![connection queryErrored]; } - return structureCopyResult; + return structureCopySuccess; +} + +- (BOOL)copyTables:(NSArray *)tablesArray from:(NSString *)sourceDB to:(NSString *)targetDB withContent:(BOOL)copyWithContent +{ + BOOL success = YES; + + //disable foreign key checks + [connection queryString:@"/*!32352 SET foreign_key_checks=0 */"]; + if([connection queryErrored]) + success = NO; + + //copy tables + for(NSString *tableName in tablesArray) { + if(![self copyTable:tableName from:sourceDB to:targetDB withContent:copyWithContent]) + success = NO; + } + + //enable foreign key checks + [connection queryString:@"/*!32352 SET foreign_key_checks=1 */"]; + if([connection queryErrored]) + success = NO; + + //done + return success; } - (BOOL)moveTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB -- cgit v1.2.3