aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseRename.m
diff options
context:
space:
mode:
authorAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
committerAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
commit57a6f6c73bdaa202164645370d37fcbe5d14a092 (patch)
treedd30aa6156064f1d4c0e10ea87059625470fc2f9 /Source/SPDatabaseRename.m
parentb5e972f4504043dfb9c358e272e93fb59ae2127f (diff)
parent0f0c43eb74408b6a65a42e2c6fd46f4142ef8e3f (diff)
downloadsequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.gz
sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.bz2
sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.zip
Merge remote-tracking branch 'sequelpro/master'
Diffstat (limited to 'Source/SPDatabaseRename.m')
-rw-r--r--Source/SPDatabaseRename.m53
1 files changed, 19 insertions, 34 deletions
diff --git a/Source/SPDatabaseRename.m b/Source/SPDatabaseRename.m
index b07f513d..04f71182 100644
--- a/Source/SPDatabaseRename.m
+++ b/Source/SPDatabaseRename.m
@@ -37,7 +37,6 @@
@interface SPDatabaseRename ()
-- (BOOL)_createDatabase:(NSString *)database;
- (BOOL)_dropDatabase:(NSString *)database;
- (void)_moveTables:(NSArray *)tables fromDatabase:(NSString *)sourceDatabase toDatabase:(NSString *)targetDatabase;
@@ -47,33 +46,32 @@
@implementation SPDatabaseRename
-- (BOOL)renameDatabaseFrom:(NSString *)sourceDatabase to:(NSString *)targetDatabase
+- (BOOL)renameDatabaseFrom:(SPCreateDatabaseInfo *)sourceDatabase to:(NSString *)targetDatabase
{
- NSArray *tables = nil;
- NSArray *views = nil;
-
// Check, whether the source database exists and the target database doesn't
- BOOL sourceExists = [[connection databases] containsObject:sourceDatabase];
+ BOOL sourceExists = [[connection databases] containsObject:[sourceDatabase databaseName]];
BOOL targetExists = [[connection databases] containsObject:targetDatabase];
- if (sourceExists && !targetExists) {
- tables = [tablesList allTableNames];
- views = [tablesList allViewNames];
- }
- else {
- return NO;
- }
-
- BOOL success = [self _createDatabase:targetDatabase];
+ if (!sourceExists || targetExists) return NO;
+
+ NSArray *tables = [tablesList allTableNames];
+ NSArray *views = [tablesList allViewNames];
- [self _moveTables:tables fromDatabase:sourceDatabase toDatabase:targetDatabase];
+ BOOL success = [self createDatabase:targetDatabase
+ withEncoding:[sourceDatabase defaultEncoding]
+ collation:[sourceDatabase defaultCollation]];
- tables = [connection tablesFromDatabase:sourceDatabase];
-
+ [self _moveTables:tables fromDatabase:[sourceDatabase databaseName] toDatabase:targetDatabase];
+
+#warning Section disabled because it might destroy data (views, functions, events, ...)
+/*
+ tables = [connection tablesFromDatabase:[sourceDatabase databaseName]];
+
if ([tables count] == 0) {
- [self _dropDatabase:sourceDatabase];
- }
-
+ [self _dropDatabase:[sourceDatabase databaseName]];
+ }
+*/
+
return success;
}
@@ -81,19 +79,6 @@
#pragma mark Private API
/**
- * This method creates a new database.
- *
- * @param NSString newDatabaseName name of the new database to be created
- * @return BOOL YES on success, otherwise NO
- */
-- (BOOL)_createDatabase:(NSString *)database
-{
- [connection queryString:[NSString stringWithFormat:@"CREATE DATABASE %@", [database backtickQuotedString]]];
-
- return ![connection queryErrored];
-}
-
-/**
* This method drops a database.
*
* @param NSString databaseName name of the database to drop