aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseRename.m
diff options
context:
space:
mode:
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