diff options
author | Abhi Beckert <abhi@Twist-of-Lemon-2.local> | 2015-05-16 08:06:06 +1000 |
---|---|---|
committer | Abhi Beckert <abhi@Twist-of-Lemon-2.local> | 2015-05-16 08:06:06 +1000 |
commit | 57a6f6c73bdaa202164645370d37fcbe5d14a092 (patch) | |
tree | dd30aa6156064f1d4c0e10ea87059625470fc2f9 /Source/SPDatabaseCopy.m | |
parent | b5e972f4504043dfb9c358e272e93fb59ae2127f (diff) | |
parent | 0f0c43eb74408b6a65a42e2c6fd46f4142ef8e3f (diff) | |
download | sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.gz sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.bz2 sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.zip |
Merge remote-tracking branch 'sequelpro/master'
Diffstat (limited to 'Source/SPDatabaseCopy.m')
-rw-r--r-- | Source/SPDatabaseCopy.m | 34 |
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 |