aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseDocument.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-03-12 02:17:31 +0100
committerMax <post@wickenrode.com>2015-03-12 02:17:31 +0100
commit8cc66aa348870e6cdf086500515848b07ea5aa06 (patch)
tree4b5c9ff7a7df2f85da06c0342cda7741f6584b32 /Source/SPDatabaseDocument.m
parent8b1ff9c9b8a996ff0c6321e58709c25f0c5763c1 (diff)
downloadsequelpro-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/SPDatabaseDocument.m')
-rw-r--r--Source/SPDatabaseDocument.m38
1 files changed, 20 insertions, 18 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 7f531f60..506e78f6 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -2769,6 +2769,17 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
return tablesListInstance;
}
+- (SPCreateDatabaseInfo *)createDatabaseInfo
+{
+ SPCreateDatabaseInfo *dbInfo = [[SPCreateDatabaseInfo alloc] init];
+
+ [dbInfo setDatabaseName:[self database]];
+ [dbInfo setDefaultEncoding:[databaseDataInstance getDatabaseDefaultCharacterSet]];
+ [dbInfo setDefaultCollation:[databaseDataInstance getDatabaseDefaultCollation]];
+
+ return [dbInfo autorelease];
+}
+
#pragma mark -
#pragma mark Notification center methods
@@ -5903,7 +5914,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
BOOL copyWithContent = [copyDatabaseDataButton state] == NSOnState;
- if ([dbActionCopy copyDatabaseFrom:[self database] to:[databaseCopyNameField stringValue] withContent:copyWithContent]) {
+ if ([dbActionCopy copyDatabaseFrom:[self createDatabaseInfo] to:[databaseCopyNameField stringValue] withContent:copyWithContent]) {
[self selectDatabase:[databaseCopyNameField stringValue] item:nil];
}
else {
@@ -5934,7 +5945,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[dbActionRename setConnection:[self getConnection]];
[dbActionRename setMessageWindow:parentWindow];
- if ([dbActionRename renameDatabaseFrom:[self database] to:newDatabaseName]) {
+ if ([dbActionRename renameDatabaseFrom:[self createDatabaseInfo] to:newDatabaseName]) {
[self setDatabases:self];
[self selectDatabase:newDatabaseName item:nil];
}
@@ -5974,25 +5985,16 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
// As we're amending identifiers, ensure UTF8
if (![[mySQLConnection encoding] isEqualToString:@"utf8"]) [mySQLConnection setEncoding:@"utf8"];
- NSString *createStatement = [NSString stringWithFormat:@"CREATE DATABASE %@", [[databaseNameField stringValue] backtickQuotedString]];
-
- // If there is an encoding selected other than the default we must specify it in CREATE DATABASE statement
- NSString *encodingName = [addDatabaseCharsetHelper selectedCharset];
- if (encodingName)
- createStatement = [NSString stringWithFormat:@"%@ DEFAULT CHARACTER SET %@", createStatement, [encodingName backtickQuotedString]];
+ SPDatabaseAction *dbAction = [[SPDatabaseAction alloc] init];
+ [dbAction setConnection:mySQLConnection];
+ BOOL res = [dbAction createDatabase:[databaseNameField stringValue]
+ withEncoding:[addDatabaseCharsetHelper selectedCharset]
+ collation:[addDatabaseCharsetHelper selectedCollation]];
+ [dbAction release];
- // If there is a collation selected other than the default we must specify it in the CREATE DATABASE statement
- NSString *collationName = [addDatabaseCharsetHelper selectedCollation];
- if (collationName)
- createStatement = [NSString stringWithFormat:@"%@ DEFAULT COLLATE %@", createStatement, [collationName backtickQuotedString]];
-
- // Create the database
- [mySQLConnection queryString:createStatement];
-
- if ([mySQLConnection queryErrored]) {
+ if (!res) {
// An error occurred
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't create database.\nMySQL said: %@", @"message of panel when creation of db failed"), [mySQLConnection lastErrorMessage]]);
-
return;
}