aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableCopy.m
diff options
context:
space:
mode:
authordmoagx <post@wickenrode.com>2011-07-06 18:47:44 +0000
committerdmoagx <post@wickenrode.com>2011-07-06 18:47:44 +0000
commit4b071f5866460dbff1bce10a297f3b017dfea26b (patch)
tree23b84a5303e7a6e53f5326ded76e341d9ece888b /Source/SPTableCopy.m
parentd86a86be46ecd2912171d1532e24a4a49afe0f5c (diff)
downloadsequelpro-4b071f5866460dbff1bce10a297f3b017dfea26b.tar.gz
sequelpro-4b071f5866460dbff1bce10a297f3b017dfea26b.tar.bz2
sequelpro-4b071f5866460dbff1bce10a297f3b017dfea26b.zip
* 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)
Diffstat (limited to 'Source/SPTableCopy.m')
-rw-r--r--Source/SPTableCopy.m36
1 files changed, 29 insertions, 7 deletions
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