From 552d01b14d97cdd325ed433bca2945c9a13061b3 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sat, 2 Mar 2013 19:07:11 +0000 Subject: - 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 --- Source/SPDatabaseDocument.m | 51 ++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 38 deletions(-) (limited to 'Source/SPDatabaseDocument.m') 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 -- cgit v1.2.3