diff options
author | rowanbeentje <rowan@beent.je> | 2013-03-02 19:07:11 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2013-03-02 19:07:11 +0000 |
commit | 552d01b14d97cdd325ed433bca2945c9a13061b3 (patch) | |
tree | 155f29f9257783e7ecd709a2f7da567451f2ac99 | |
parent | e01f4a945279605ae5b674b61e0bee752e8d933d (diff) | |
download | sequelpro-552d01b14d97cdd325ed433bca2945c9a13061b3.tar.gz sequelpro-552d01b14d97cdd325ed433bca2945c9a13061b3.tar.bz2 sequelpro-552d01b14d97cdd325ed433bca2945c9a13061b3.zip |
- Alter the database creation sheet to correctly use the selected new database encoding
- Clean up the database creation logic and remove redundant selection logic
- Correctly reset and detect the database encoding when creating and switching databases
-rw-r--r-- | Source/SPDatabaseData.m | 4 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 51 |
2 files changed, 16 insertions, 39 deletions
diff --git a/Source/SPDatabaseData.m b/Source/SPDatabaseData.m index 6bf72d5e..202f56ce 100644 --- a/Source/SPDatabaseData.m +++ b/Source/SPDatabaseData.m @@ -79,7 +79,9 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo, */ - (void)resetAllData { - if (characterSetEncoding != nil) [characterSetEncoding release], characterSetEncoding = nil; + if (characterSetEncoding != nil) [characterSetEncoding release], characterSetEncoding = nil; + if (defaultCollation != nil) [defaultCollation release], defaultCollation = nil; + if (defaultCharacterSetEncoding != nil) [defaultCharacterSetEncoding release], defaultCharacterSetEncoding = nil; [collations removeAllObjects]; [characterSetCollations removeAllObjects]; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index eb61c6fc..f8b673ff 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -98,6 +98,7 @@ enum { #import "SPConnectionDelegate.h" #endif #import "SPThreadAdditions.h" +#import "RegexKitLite.h" #ifdef SP_CODA /* headers */ #import "SPAlertSheets.h" @@ -5882,7 +5883,11 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; // If there is an encoding selected other than the default we must specify it in CREATE DATABASE statement if ([databaseEncodingButton indexOfSelectedItem] > 0) { - createStatement = [NSString stringWithFormat:@"%@ DEFAULT CHARACTER SET %@", createStatement, [[self mysqlEncodingFromEncodingTag:[NSNumber numberWithInteger:[databaseEncodingButton tag]]] backtickQuotedString]]; + NSString *encodingName = [[databaseEncodingButton title] stringByMatching:@"\\((.*)\\)\\Z" capture:1L]; + if (!encodingName) encodingName = [databaseEncodingButton title]; + if (!encodingName) encodingName = @"utf8"; + + createStatement = [NSString stringWithFormat:@"%@ DEFAULT CHARACTER SET %@", createStatement, [encodingName backtickQuotedString]]; } // Create the database @@ -5894,41 +5899,15 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; return; } - - // Error while selecting the new database (is this even possible?) - if (![mySQLConnection selectDatabase:[databaseNameField stringValue]] ) { - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to database %@.\nBe sure that you have the necessary privileges.", @"message of panel when connection to db failed after selecting from popupbutton"), [databaseNameField stringValue]]); - - [self setDatabases:self]; - - return; - } - - // Select the new database - if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; - - - selectedDatabase = [[NSString alloc] initWithString:[databaseNameField stringValue]]; + [self setDatabases:self]; - - [tablesListInstance setConnection:mySQLConnection]; - [tableDumpInstance setConnection:mySQLConnection]; - -#ifndef SP_CODA - [self updateWindowTitle:self]; -#endif #ifdef SP_CODA /* glue */ if ( delegate && [delegate respondsToSelector:@selector(refreshDatabasePopup)] ) [delegate performSelector:@selector(refreshDatabasePopup) withObject:nil]; - - if ( delegate && [delegate respondsToSelector:@selector(selectDatabaseInPopup:)] ) - { - if ( [allDatabases count] > 0 ) - { - [delegate performSelector:@selector(selectDatabaseInPopup:) withObject:selectedDatabase]; - } - } #endif + + // Select the database + [self selectDatabase:[databaseNameField stringValue] item:nil]; } /** @@ -5965,7 +5944,6 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; [self setDatabases:self]; [tablesListInstance setConnection:mySQLConnection]; - [tableDumpInstance setConnection:mySQLConnection]; #ifndef SP_CODA [self updateWindowTitle:self]; @@ -6032,11 +6010,9 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; [[chooseDatabaseButton onMainThread] selectItemWithTitle:targetDatabaseName]; #endif if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; -#ifndef SP_CODA /* patch */ - selectedDatabase = [[NSString alloc] initWithString:[chooseDatabaseButton titleOfSelectedItem]]; -#else selectedDatabase = [[NSString alloc] initWithString:targetDatabaseName]; -#endif + + [databaseDataInstance resetAllData]; #ifndef SP_CODA /* update database encoding */ @@ -6045,9 +6021,8 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; [self detectDatabaseEncoding]; #endif - // Set the connection of SPTablesList and TablesDump to reload tables in db + // Set the connection of SPTablesList to reload tables in db [tablesListInstance setConnection:mySQLConnection]; - [tableDumpInstance setConnection:mySQLConnection]; #ifndef SP_CODA /* update history controller and ui manip */ // Update the window title |