aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPDatabaseDocument.h2
-rw-r--r--Source/SPDatabaseDocument.m29
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