diff options
author | stuconnolly <stuart02@gmail.com> | 2012-05-04 14:36:30 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-05-04 14:36:30 +0000 |
commit | 5544489096885e4e4be1ab6e54160caaa44c03dc (patch) | |
tree | 52b2201bf491d1e3495d506e7c282b3509e33808 /Source/SPTableCopy.m | |
parent | 830790b9251a36f3d1290a3f9ead62195d61f00a (diff) | |
download | sequelpro-5544489096885e4e4be1ab6e54160caaa44c03dc.tar.gz sequelpro-5544489096885e4e4be1ab6e54160caaa44c03dc.tar.bz2 sequelpro-5544489096885e4e4be1ab6e54160caaa44c03dc.zip |
Add initial support of moving views when renaming a database. Currently not hooked up yet. Part of issue #1235.
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 |