aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseAction.m
diff options
context:
space:
mode:
authorAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
committerAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
commit57a6f6c73bdaa202164645370d37fcbe5d14a092 (patch)
treedd30aa6156064f1d4c0e10ea87059625470fc2f9 /Source/SPDatabaseAction.m
parentb5e972f4504043dfb9c358e272e93fb59ae2127f (diff)
parent0f0c43eb74408b6a65a42e2c6fd46f4142ef8e3f (diff)
downloadsequelpro-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.m48
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