diff options
author | rowanbeentje <rowan@beent.je> | 2011-09-29 22:11:44 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2011-09-29 22:11:44 +0000 |
commit | c9aad8326e53f9544bc10e9bae6bb2a7697cbffa (patch) | |
tree | af50bb641464fbca695e4e2e73e5e4e3be6a87e8 /Source | |
parent | 8beaf3610a50d8e0735301f9630db61fa182db74 (diff) | |
download | sequelpro-c9aad8326e53f9544bc10e9bae6bb2a7697cbffa.tar.gz sequelpro-c9aad8326e53f9544bc10e9bae6bb2a7697cbffa.tar.bz2 sequelpro-c9aad8326e53f9544bc10e9bae6bb2a7697cbffa.zip |
- Update database encoding routines to cache the database encoding, preventing repeated calls when navigating tables using "default" encoding, or views
- Ensure the database encoding is correctly updated when new databases are selected. This addresses Issue #1201
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPDatabaseDocument.h | 2 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 29 |
2 files changed, 25 insertions, 6 deletions
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index d79610e9..b56991f5 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -167,6 +167,7 @@ SPDatabaseData, SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPS NSString *selectedDatabase; NSString *mySQLVersion; + NSString *selectedDatabaseEncoding; #ifndef SP_REFACTOR /* ivars */ NSUserDefaults *prefs; NSMutableArray *nibObjectsToRelease; @@ -325,6 +326,7 @@ SPDatabaseData, SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPS // Encoding methods - (void)setConnectionEncoding:(NSString *)mysqlEncoding reloadingViews:(BOOL)reloadViews; - (NSString *)databaseEncoding; +- (void)detectDatabaseEncoding; - (IBAction)chooseEncoding:(id)sender; - (BOOL)supportsEncoding; - (void)updateEncodingMenuWithSelectedEncoding:(NSNumber *)encodingTag; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 4d8f2095..2133cfcd 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -163,6 +163,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; triggersLoaded = NO; selectedDatabase = nil; + selectedDatabaseEncoding = [[NSString alloc] initWithString:@"latin1"]; mySQLConnection = nil; mySQLVersion = nil; allDatabases = nil; @@ -549,7 +550,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } } - if ([self database]) (void)[self databaseEncoding]; + if ([self database]) [self detectDatabaseEncoding]; #endif #ifdef SP_REFACTOR /* glue */ if ( delegate && [delegate respondsToSelector:@selector(databaseDocumentDidConnect:)] ) @@ -1535,11 +1536,20 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } /** - * Detect and return the database encoding. - * Falls back to Latin1. + * Retrieve the current database encoding. This will return Latin-1 + * for unknown encodings. */ - (NSString *)databaseEncoding { + return selectedDatabaseEncoding; +} + +/** + * Detect and store the encoding of the currently selected database. + * Falls back to Latin-1 if the encoding cannot be retrieved. + */ +- (void)detectDatabaseEncoding +{ MCPResult *charSetResult; NSString *mysqlEncoding = nil; @@ -1556,14 +1566,16 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] fetchRowAsDictionary] objectForKey:@"Value"]; } + [selectedDatabaseEncoding release]; + // Fallback or older version? -> set encoding to mysql default encoding latin1 if ( !mysqlEncoding ) { NSLog(@"Error: no character encoding found, mysql version is %@", [self mySQLVersion]); - mysqlEncoding = @"latin1"; + selectedDatabaseEncoding = [[NSString alloc] initWithString:@"latin1"]; _supportsEncoding = NO; + } else { + selectedDatabaseEncoding = [mysqlEncoding retain]; } - - return mysqlEncoding; } /** @@ -5651,6 +5663,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [undoManager release]; [printWebView release]; #endif + [selectedDatabaseEncoding release]; [taskProgressWindow close]; if (selectedTableName) [selectedTableName release]; @@ -5953,6 +5966,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [[[tablesListInstance valueForKey:@"tablesListView"] onMainThread] deselectAll:self]; [[tablesListInstance onMainThread] setTableListSelectability:NO]; } + + // Update the stored database encoding, used for views, "default" table encodings, and to allow + // or disallow use of the "View using encoding" menu + [self detectDatabaseEncoding]; #endif // Set the connection of SPTablesList and TablesDump to reload tables in db |