aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SPTableInfo.m4
-rw-r--r--TableDocument.h6
-rw-r--r--TableDocument.m45
-rw-r--r--TablesList.h4
-rw-r--r--TablesList.m14
5 files changed, 49 insertions, 24 deletions
diff --git a/SPTableInfo.m b/SPTableInfo.m
index 5e777429..5f395c59 100644
--- a/SPTableInfo.m
+++ b/SPTableInfo.m
@@ -114,9 +114,6 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
// Process result
theRow = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject];
- // Add the table name to the infoTable
- [info addObject:[NSString stringWithFormat:@"name: %@", [tableListInstance table]]];
-
// Check for "Create_time" == NULL
if (![[theRow objectForKey:@"Create_time"] isNSNull]) {
// Setup our data formatter
@@ -135,6 +132,7 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
[info addObject:[NSString stringWithFormat:@"rows: %@", [theRow objectForKey:@"Rows"]]];
[info addObject:[NSString stringWithFormat:@"size: %@", [self sizeFromBytes:[[theRow objectForKey:@"Data_length"] intValue]]]];
+ [info addObject:[NSString stringWithFormat:@"encoding: %@", [[[theRow objectForKey:@"Collation"] componentsSeparatedByString:@"_"] objectAtIndex:0]]];
[info addObject:[NSString stringWithFormat:@"auto_increment: %@", [theRow objectForKey:@"Auto_increment"]]];
// Notify that we've finished performing the query
diff --git a/TableDocument.h b/TableDocument.h
index ac20b335..62798b2d 100644
--- a/TableDocument.h
+++ b/TableDocument.h
@@ -134,7 +134,8 @@
//encoding methods
- (void)setEncoding:(NSString *)encoding;
-- (void)detectEncoding;
+- (void)detectDatabaseEncoding;
+- (void)detectTableEncodingForTable:(NSString *)table;
- (IBAction)chooseEncoding:(id)sender;
- (BOOL)supportsEncoding;
- (void)updateEncodingMenuWithSelectedEncoding:(NSString *)encoding;
@@ -214,9 +215,6 @@
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex;
-//for freeing up memory
-- (void)dealloc;
-
@end
extern NSString *TableDocumentFavoritesControllerSelectionIndexDidChange;
diff --git a/TableDocument.m b/TableDocument.m
index e88a62ad..8ca7b0ae 100644
--- a/TableDocument.m
+++ b/TableDocument.m
@@ -182,7 +182,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
// set encoding
NSString *encodingName = [prefs objectForKey:@"encoding"];
if ( [encodingName isEqualToString:@"Autodetect"] ) {
- [self detectEncoding];
+ [self detectDatabaseEncoding];
} else {
[self setEncoding:[self mysqlEncodingFromDisplayEncoding:encodingName]];
}
@@ -632,14 +632,15 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
{
// set encoding of connection and client
[mySQLConnection queryString:[NSString stringWithFormat:@"SET NAMES '%@'", mysqlEncoding]];
+
if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
[mySQLConnection setEncoding:[CMMCPConnection encodingForMySQLEncoding:[mysqlEncoding UTF8String]]];
[_encoding autorelease];
_encoding = [mysqlEncoding retain];
} else {
- [self detectEncoding];
+ [self detectDatabaseEncoding];
}
-
+
// update the selected menu item
[self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:mysqlEncoding]];
@@ -742,9 +743,9 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
/**
* Autodetect the connection encoding and select the relevant encoding menu item in Database -> Database Encoding
*/
-- (void)detectEncoding
+- (void)detectDatabaseEncoding
{
- // mysql > 4.0
+ // MySQL > 4.0
id mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set_connection'"] fetchRowAsDictionary] objectForKey:@"Value"];
_supportsEncoding = (mysqlEncoding != nil);
@@ -755,9 +756,10 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] fetchRowAsDictionary] objectForKey:@"Value"];
}
if ( !mysqlEncoding ) { // older version? -> set encoding to mysql default encoding latin1
- NSLog(@"error: no character encoding found, mysql version is %@", [self mySQLVersion]);
+ NSLog(@"Error: no character encoding found, mysql version is %@", [self mySQLVersion]);
mysqlEncoding = @"latin1";
}
+
[mySQLConnection setEncoding:[CMMCPConnection encodingForMySQLEncoding:[mysqlEncoding cString]]];
// save the encoding
@@ -769,7 +771,36 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
}
/**
- * when sent by an NSMenuItem, will set the encoding based on the title of the menu item
+ * Detects and sets the character set encoding of the supplied table name.
+ */
+- (void)detectTableEncodingForTable:(NSString *)table;
+{
+ NSString *tableCollation = [[[mySQLConnection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS WHERE NAME = '%@'", table]] fetchRowAsDictionary] objectForKey:@"Collation"];
+
+ if (tableCollation != nil) {
+ // Split up the collation string so we can get the encoding
+ NSArray *encodingComponents = [tableCollation componentsSeparatedByString:@"_"];
+
+ if ([encodingComponents count] > 0) {
+ NSString *tableEncoding = [encodingComponents objectAtIndex:0];
+
+ [mySQLConnection setEncoding:[CMMCPConnection encodingForMySQLEncoding:[tableEncoding UTF8String]]];
+
+ // Save the encoding
+ [_encoding autorelease];
+ _encoding = [tableEncoding retain];
+
+ // update the selected menu item
+ [self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:tableEncoding]];
+ }
+ }
+ else {
+ NSLog(@"Error: unable to determine table collation and thus character encoding for table '%@'", table);
+ }
+}
+
+/**
+ * When sent by an NSMenuItem, will set the encoding based on the title of the menu item
*/
- (IBAction)chooseEncoding:(id)sender
{
diff --git a/TablesList.h b/TablesList.h
index d7d37d2e..7270219b 100644
--- a/TablesList.h
+++ b/TablesList.h
@@ -92,8 +92,4 @@
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView;
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification;
-//last but not least
-- (id)init;
-- (void)dealloc;
-
@end
diff --git a/TablesList.m b/TablesList.m
index 500ac349..40ea87c5 100644
--- a/TablesList.m
+++ b/TablesList.m
@@ -543,12 +543,12 @@ traps enter and esc and edit/cancel without entering next row
}
}
-/*
-loads a table in content or source view (if tab selected)
-*/
+/**
+ * Loads a table in content or source view (if tab selected)
+ */
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
- if ( [tablesListView numberOfSelectedRows] == 1 ) {
+ if ( [tablesListView numberOfSelectedRows] == 1 ) {
if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
[tableSourceInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
structureLoaded = YES;
@@ -575,6 +575,10 @@ loads a table in content or source view (if tab selected)
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
[tableDocumentInstance host], [tableDocumentInstance database], [tables objectAtIndex:[tablesListView selectedRow]]]];
+ // Update connection characater set encoding based on the table's encoding if required
+ if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"encoding"] isEqualToString:@"Autodetect"]) {
+ [tableDocumentInstance detectTableEncodingForTable:[tables objectAtIndex:[tablesListView selectedRow]]];
+ }
} else {
[tableSourceInstance loadTable:nil];
[tableContentInstance loadTable:nil];
@@ -589,8 +593,6 @@ loads a table in content or source view (if tab selected)
}
}
-
-
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex
{
return (rowIndex != 0);