aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseAction.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPDatabaseAction.m')
-rw-r--r--Source/SPDatabaseAction.m45
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