diff options
Diffstat (limited to 'Source/SPTableCopy.m')
-rw-r--r-- | Source/SPTableCopy.m | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/Source/SPTableCopy.m b/Source/SPTableCopy.m index fd9b9055..e629e481 100644 --- a/Source/SPTableCopy.m +++ b/Source/SPTableCopy.m @@ -24,26 +24,21 @@ #import "SPDBActionCommons.h" #import "SPTableCopy.h" + #import <SPMySQL/SPMySQL.h> -@implementation SPTableCopy +@interface SPTableCopy () -- (NSString *)getCreateTableStatementFor:(NSString *)tableName inDB:(NSString *)sourceDB -{ - NSString *showCreateTableStatment = [NSString stringWithFormat:@"SHOW CREATE TABLE %@.%@", [sourceDB backtickQuotedString], [tableName backtickQuotedString]]; - - SPMySQLResult *theResult = [connection queryString:showCreateTableStatment]; - - if ([theResult numberOfRows] != 0) { - return [[theResult getRowAsArray] objectAtIndex:1]; - } - - return @""; -} +- (NSString *)_createTableStatementFor:(NSString *)tableName inDatabase:(NSString *)sourceDatabase; + +@end + + +@implementation SPTableCopy - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB { - NSString *createTableResult = [self getCreateTableStatementFor:tableName inDB:sourceDB]; + NSString *createTableResult = [self _createTableStatementFor:tableName inDatabase:sourceDB]; NSMutableString *createTableStatement = [[NSMutableString alloc] initWithString:createTableResult]; if ([[createTableStatement substringToIndex:12] isEqualToString:@"CREATE TABLE"]) { @@ -115,18 +110,29 @@ return success; } -- (BOOL)moveTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB +- (BOOL)moveTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB { NSString *moveStatement = [NSString stringWithFormat:@"RENAME TABLE %@.%@ TO %@.%@", [sourceDB backtickQuotedString], [tableName backtickQuotedString], [targetDB backtickQuotedString], - [tableName backtickQuotedString] - ]; + [tableName backtickQuotedString]]; [connection queryString:moveStatement]; return ![connection queryErrored]; } +#pragma mark - +#pragma mark Private API + +- (NSString *)_createTableStatementFor:(NSString *)tableName inDatabase:(NSString *)sourceDatabase +{ + NSString *showCreateTableStatment = [NSString stringWithFormat:@"SHOW CREATE TABLE %@.%@", [sourceDatabase backtickQuotedString], [tableName backtickQuotedString]]; + + SPMySQLResult *theResult = [connection queryString:showCreateTableStatment]; + + return [theResult numberOfRows] > 0 ? [[theResult getRowAsArray] objectAtIndex:1] : @""; +} + @end |