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/SPDatabaseAction.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/SPDatabaseAction.m')
-rw-r--r-- | Source/SPDatabaseAction.m | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/SPDatabaseAction.m b/Source/SPDatabaseAction.m index 998aff95..413e2378 100644 --- a/Source/SPDatabaseAction.m +++ b/Source/SPDatabaseAction.m @@ -30,10 +30,58 @@ #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 +{ + if(![database length]) { + SPLog(@"'database' should not be nil or empty!"); + return NO; + } + + 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 |