diff options
author | Max <post@wickenrode.com> | 2015-03-12 02:17:31 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-03-12 02:17:31 +0100 |
commit | 8cc66aa348870e6cdf086500515848b07ea5aa06 (patch) | |
tree | 4b5c9ff7a7df2f85da06c0342cda7741f6584b32 /Source/SPDatabaseRename.m | |
parent | 8b1ff9c9b8a996ff0c6321e58709c25f0c5763c1 (diff) | |
download | sequelpro-8cc66aa348870e6cdf086500515848b07ea5aa06.tar.gz sequelpro-8cc66aa348870e6cdf086500515848b07ea5aa06.tar.bz2 sequelpro-8cc66aa348870e6cdf086500515848b07ea5aa06.zip |
Fix Sequel Pro forgetting database charset when renaming or copying a database (#2082)
(While we're at it, also removed some duplicate CREATE DATABASE code)
Diffstat (limited to 'Source/SPDatabaseRename.m')
-rw-r--r-- | Source/SPDatabaseRename.m | 53 |
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 |