aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableCopy.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-05-04 14:36:30 +0000
committerstuconnolly <stuart02@gmail.com>2012-05-04 14:36:30 +0000
commit5544489096885e4e4be1ab6e54160caaa44c03dc (patch)
tree52b2201bf491d1e3495d506e7c282b3509e33808 /Source/SPTableCopy.m
parent830790b9251a36f3d1290a3f9ead62195d61f00a (diff)
downloadsequelpro-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.m40
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