aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseCopy.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-03-12 02:17:31 +0100
committerMax <post@wickenrode.com>2015-03-12 02:17:31 +0100
commit8cc66aa348870e6cdf086500515848b07ea5aa06 (patch)
tree4b5c9ff7a7df2f85da06c0342cda7741f6584b32 /Source/SPDatabaseCopy.m
parent8b1ff9c9b8a996ff0c6321e58709c25f0c5763c1 (diff)
downloadsequelpro-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/SPDatabaseCopy.m')
-rw-r--r--Source/SPDatabaseCopy.m34
1 files changed, 11 insertions, 23 deletions
diff --git a/Source/SPDatabaseCopy.m b/Source/SPDatabaseCopy.m
index 5ea0a2d5..94a5e896 100644
--- a/Source/SPDatabaseCopy.m
+++ b/Source/SPDatabaseCopy.m
@@ -35,46 +35,34 @@
@implementation SPDatabaseCopy
-- (BOOL)copyDatabaseFrom:(NSString *)sourceDatabaseName to:(NSString *)targetDatabaseName withContent:(BOOL)copyWithContent
+- (BOOL)copyDatabaseFrom:(SPCreateDatabaseInfo *)sourceDatabase to:(NSString *)targetDatabaseName withContent:(BOOL)copyWithContent
{
NSArray *tables = nil;
// Check whether the source database exists and the target database doesn't.
- BOOL sourceExists = [[connection databases] containsObject:sourceDatabaseName];
+ BOOL sourceExists = [[connection databases] containsObject:[sourceDatabase databaseName]];
BOOL targetExists = [[connection databases] containsObject:targetDatabaseName];
- if (sourceExists && !targetExists) {
-
- // Retrieve the list of tables/views/funcs/triggers from the source database
- tables = [connection tablesFromDatabase:sourceDatabaseName];
- }
- else {
+ if (!sourceExists || targetExists)
return NO;
- }
-
+
+ // Retrieve the list of tables/views/funcs/triggers from the source database
+ tables = [connection tablesFromDatabase:[sourceDatabase databaseName]];
+
// Abort if database creation failed
- if (![self createDatabase:targetDatabaseName]) return NO;
+ if (![self createDatabase:targetDatabaseName
+ withEncoding:[sourceDatabase defaultEncoding]
+ collation:[sourceDatabase defaultCollation]]) return NO;
SPTableCopy *dbActionTableCopy = [[SPTableCopy alloc] init];
[dbActionTableCopy setConnection:connection];
- BOOL success = [dbActionTableCopy copyTables:tables from:sourceDatabaseName to:targetDatabaseName withContent:copyWithContent];
+ BOOL success = [dbActionTableCopy copyTables:tables from:[sourceDatabase databaseName] to:targetDatabaseName withContent:copyWithContent];
[dbActionTableCopy release];
return success;
}
-- (BOOL)createDatabase:(NSString *)newDatabaseName
-{
- NSString *createStatement = [NSString stringWithFormat:@"CREATE DATABASE %@", [newDatabaseName backtickQuotedString]];
-
- [connection queryString:createStatement];
-
- if ([connection queryErrored]) return NO;
-
- return YES;
-}
-
@end