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/SPDatabaseAction.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/SPDatabaseAction.m')
-rw-r--r-- | Source/SPDatabaseAction.m | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Source/SPDatabaseAction.m b/Source/SPDatabaseAction.m index 998aff95..f5ed8b60 100644 --- a/Source/SPDatabaseAction.m +++ b/Source/SPDatabaseAction.m @@ -30,10 +30,55 @@ #import "SPDatabaseAction.h" +#import <SPMySQL/SPMySQL.h> + +@implementation SPCreateDatabaseInfo + +@synthesize databaseName; +@synthesize defaultEncoding; +@synthesize defaultCollation; + +- (void)dealloc +{ + [self setDatabaseName:nil]; + [self setDefaultEncoding:nil]; + [self setDefaultCollation:nil]; + [super dealloc]; +} + +@end + +#pragma mark - + @implementation SPDatabaseAction @synthesize connection; @synthesize messageWindow; @synthesize tablesList; +- (BOOL)createDatabase:(SPCreateDatabaseInfo *)dbInfo +{ + return [self createDatabase:[dbInfo databaseName] + withEncoding:[dbInfo defaultEncoding] + collation:[dbInfo defaultCollation]]; +} + +- (BOOL)createDatabase:(NSString *)database withEncoding:(NSString *)encoding collation:(NSString *)collation +{ + NSParameterAssert(database != nil && [database length] > 0); + + NSMutableString *query = [NSMutableString stringWithFormat:@"CREATE DATABASE %@", [database backtickQuotedString]]; + + if([encoding length]) { // [nil length] == 0 + [query appendFormat:@" DEFAULT CHARACTER SET = %@",[encoding backtickQuotedString]]; + if([collation length]) { + [query appendFormat:@" DEFAULT COLLATE = %@",[collation backtickQuotedString]]; + } + } + + [connection queryString:query]; + + return ![connection queryErrored]; +} + @end |