diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMMCPConnection.h | 1 | ||||
-rw-r--r-- | Source/CMMCPConnection.m | 93 | ||||
-rw-r--r-- | Source/TableDocument.m | 22 |
3 files changed, 82 insertions, 34 deletions
diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index f07c9786..584b8056 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -62,6 +62,7 @@ - (void) disconnect; - (BOOL) reconnect; - (IBAction) closeSheet:(id)sender; ++ (NSStringEncoding) encodingForMySQLEncoding:(const char *) mysqlEncoding; - (void) setParentWindow:(NSWindow *)theWindow; - (BOOL) selectDB:(NSString *) dbName; - (CMMCPResult *) queryString:(NSString *) query; diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index df1de415..14cd6ba7 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -214,23 +214,26 @@ static void forcePingTimeout(int signalNumber); } /* -Gets a proper NSStringEncoding according to the given MySQL charset. - -MySQL 4.0 offers this charsets: -big5 cp1251 cp1257 croat czech danish dec8 dos estonia euc_kr gb2312 gbk german1 greek hebrew hp8 hungarian koi8_ru koi8_ukr latin1 latin1_de latin2 latin5 sjis swe7 tis620 ujis usa7 win1250 win1251ukr - -WARNING : incomplete implementation. Please, send your fixes. - + * Gets a proper NSStringEncoding according to the given MySQL charset. + * + * MySQL 4.0 offers this charsets: + * big5 cp1251 cp1257 croat czech danish dec8 dos estonia euc_kr gb2312 gbk german1 + * greek hebrew hp8 hungarian koi8_ru koi8_ukr latin1 latin1_de latin2 latin5 sjis + * swe7 tis620 ujis usa7 win1250 win1251ukr + * + * WARNING : incomplete implementation. Please, send your fixes. + */ + (NSStringEncoding) encodingForMySQLEncoding:(const char *) mysqlEncoding { - // unicode + // Unicode encodings: if (!strncmp(mysqlEncoding, "utf8", 4)) { return NSUTF8StringEncoding; } if (!strncmp(mysqlEncoding, "ucs2", 4)) { return NSUnicodeStringEncoding; } - // west european + + // Roman alphabet encodings: if (!strncmp(mysqlEncoding, "ascii", 5)) { return NSASCIIStringEncoding; } @@ -240,50 +243,76 @@ WARNING : incomplete implementation. Please, send your fixes. if (!strncmp(mysqlEncoding, "macroman", 8)) { return NSMacOSRomanStringEncoding; } - // central european - if (!strncmp(mysqlEncoding, "cp1250", 6)) { - return NSWindowsCP1250StringEncoding; - } + + // Roman alphabet with central/east european additions: if (!strncmp(mysqlEncoding, "latin2", 6)) { return NSISOLatin2StringEncoding; } - // south european and middle east - if (!strncmp(mysqlEncoding, "cp1256", 6)) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic); + if (!strncmp(mysqlEncoding, "cp1250", 6)) { + return NSWindowsCP1250StringEncoding; } - if (!strncmp(mysqlEncoding, "greek", 5)) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinGreek); + if (!strncmp(mysqlEncoding, "win1250", 7)) { + return NSWindowsCP1250StringEncoding; } - if (!strncmp(mysqlEncoding, "hebrew", 6)) { - CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinHebrew); + if (!strncmp(mysqlEncoding, "cp1257", 6)) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsBalticRim); } + + // Additions for Turkish: if (!strncmp(mysqlEncoding, "latin5", 6)) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin5); + return NSWindowsCP1254StringEncoding; } - // baltic - if (!strncmp(mysqlEncoding, "cp1257", 6)) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsBalticRim); + + // Greek: + if (!strncmp(mysqlEncoding, "greek", 5)) { + return NSWindowsCP1253StringEncoding; + } + + // Cyrillic: + if (!strncmp(mysqlEncoding, "win1251ukr", 6)) { + return NSWindowsCP1251StringEncoding; } - // cyrillic if (!strncmp(mysqlEncoding, "cp1251", 6)) { return NSWindowsCP1251StringEncoding; } - // asian - if (!strncmp(mysqlEncoding, "big5", 4)) { - return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingBig5); + if (!strncmp(mysqlEncoding, "koi8_ru", 6)) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingKOI8_R); + } + if (!strncmp(mysqlEncoding, "koi8_ukr", 6)) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingKOI8_R); + } + + // Arabic: + if (!strncmp(mysqlEncoding, "cp1256", 6)) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic); + } + + // Hebrew: + if (!strncmp(mysqlEncoding, "hebrew", 6)) { + CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinHebrew); } + + // Asian: if (!strncmp(mysqlEncoding, "ujis", 4)) { return NSJapaneseEUCStringEncoding; } if (!strncmp(mysqlEncoding, "sjis", 4)) { return NSShiftJISStringEncoding; } - - // default to iso latin 1, even if it is not exact (throw an exception?) - NSLog(@"warning: unknown encoding %s! falling back to latin1.", mysqlEncoding); + if (!strncmp(mysqlEncoding, "big5", 4)) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingBig5); + } + if (!strncmp(mysqlEncoding, "euc_kr", 6)) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_KR); + } + if (!strncmp(mysqlEncoding, "euckr", 5)) { + return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_KR); + } + + // Default to iso latin 1, even if it is not exact (throw an exception?) + NSLog(@"WARNING : unknown name for MySQL encoding '%s'!\n\t\tFalling back to iso-latin1.", mysqlEncoding); return NSISOLatin1StringEncoding; } -*/ /* diff --git a/Source/TableDocument.m b/Source/TableDocument.m index ea02dd20..6957ae4d 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -606,10 +606,20 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa */ - (void)setConnectionEncoding:(NSString *)mysqlEncoding reloadingViews:(BOOL)reloadViews { + BOOL uselatin1results = NO; + + // Special-case UTF-8 over latin 1 to allow viewing/editing of mangled data. + if ([mysqlEncoding isEqualToString:@"utf8-"]) { + uselatin1results = YES; + mysqlEncoding = @"utf8"; + } + // set encoding of connection and client [mySQLConnection queryString:[NSString stringWithFormat:@"SET NAMES '%@'", mysqlEncoding]]; if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { + if (uselatin1results) + [mySQLConnection queryString:@"SET CHARACTER_SET_RESULTS=latin1"]; [mySQLConnection setEncoding:[CMMCPConnection encodingForMySQLEncoding:[mysqlEncoding UTF8String]]]; [_encoding autorelease]; _encoding = [mysqlEncoding retain]; @@ -622,8 +632,12 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa } // update the selected menu item - [self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:mysqlEncoding]]; - + if (uselatin1results) { + [self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:[NSString stringWithFormat:@"%@-", mysqlEncoding]]]; + } else { + [self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:mysqlEncoding]]; + } + // Reload stuff as appropriate [tableDataInstance resetAllData]; if (reloadViews) { @@ -669,6 +683,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa NSDictionary *translationMap = [NSDictionary dictionaryWithObjectsAndKeys: @"UCS-2 Unicode (ucs2)", @"ucs2", @"UTF-8 Unicode (utf8)", @"utf8", + @"UTF-8 Unicode via Latin 1", @"utf8-", @"US ASCII (ascii)", @"ascii", @"ISO Latin 1 (latin1)", @"latin1", @"Mac Roman (macroman)", @"macroman", @@ -683,6 +698,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa @"Big5 Traditional Chinese (big5)", @"big5", @"Shift-JIS Japanese (sjis)", @"sjis", @"EUC-JP Japanese (ujis)", @"ujis", + @"EUC-KR Korean (euckr)", @"euckr", nil]; NSString *encodingName = [translationMap valueForKey:mysqlEncoding]; @@ -700,6 +716,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa NSDictionary *translationMap = [NSDictionary dictionaryWithObjectsAndKeys: @"ucs2", @"UCS-2 Unicode (ucs2)", @"utf8", @"UTF-8 Unicode (utf8)", + @"utf8-", @"UTF-8 Unicode via Latin 1", @"ascii", @"US ASCII (ascii)", @"latin1", @"ISO Latin 1 (latin1)", @"macroman", @"Mac Roman (macroman)", @@ -714,6 +731,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa @"big5", @"Big5 Traditional Chinese (big5)", @"sjis", @"Shift-JIS Japanese (sjis)", @"ujis", @"EUC-JP Japanese (ujis)", + @"euckr", @"EUC-KR Korean (euckr)", nil]; NSString *mysqlEncoding = [translationMap valueForKey:encodingName]; |