aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseDocument.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2011-09-29 22:11:44 +0000
committerrowanbeentje <rowan@beent.je>2011-09-29 22:11:44 +0000
commitc9aad8326e53f9544bc10e9bae6bb2a7697cbffa (patch)
treeaf50bb641464fbca695e4e2e73e5e4e3be6a87e8 /Source/SPDatabaseDocument.m
parent8beaf3610a50d8e0735301f9630db61fa182db74 (diff)
downloadsequelpro-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/SPDatabaseDocument.m')
-rw-r--r--Source/SPDatabaseDocument.m29
1 files changed, 23 insertions, 6 deletions
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