aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConstants.h24
-rw-r--r--Source/SPConstants.m2
-rw-r--r--Source/SPDatabaseData.m26
-rw-r--r--Source/SPDatabaseDocument.h6
-rw-r--r--Source/SPDatabaseDocument.m144
-rw-r--r--Source/SPPreferenceController.m41
-rw-r--r--Source/SPTablesList.m33
7 files changed, 211 insertions, 65 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 99d16583..0eafec7a 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -151,6 +151,30 @@ typedef enum
SPMainMenuHelp = 7
} SPMainMenuTags;
+// Encoding constants
+typedef enum
+{
+ SPEncodingAutodetect = 0,
+ SPEncodingUCS2 = 10,
+ SPEncodingUTF8 = 20,
+ SPEncodingUTF8viaLatin1 = 30,
+ SPEncodingASCII = 40,
+ SPEncodingLatin1 = 50,
+ SPEncodingMacRoman = 60,
+ SPEncodingCP1250Latin2 = 70,
+ SPEncodingISOLatin2 = 80,
+ SPEncodingCP1256Arabic = 90,
+ SPEncodingGreek = 100,
+ SPEncodingHebrew = 110,
+ SPEncodingLatin5Turkish = 120,
+ SPEncodingCP1257WinBaltic = 130,
+ SPEncodingCP1251WinCyrillic = 140,
+ SPEncodingBig5Chinese = 150,
+ SPEncodingShiftJISJapanese = 160,
+ SPEncodingEUCJPJapanese = 170,
+ SPEncodingEUCKRKorean = 180
+} SPEncodingTypes;
+
// Long running notification time for Growl messages
extern const CGFloat SPLongRunningNotificationTime;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index 4ce1a4c5..93553d78 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -59,7 +59,7 @@ NSString *SPLastFavoriteIndex = @"LastFavoriteIndex";
NSString *SPAutoConnectToDefault = @"AutoConnectToDefault";
NSString *SPDefaultViewMode = @"DefaultViewMode";
NSString *SPLastViewMode = @"LastViewMode";
-NSString *SPDefaultEncoding = @"DefaultEncoding";
+NSString *SPDefaultEncoding = @"DefaultEncodingTag";
NSString *SPUseMonospacedFonts = @"UseMonospacedFonts";
NSString *SPDisplayTableViewVerticalGridlines = @"DisplayTableViewVerticalGridlines";
NSString *SPCustomQueryMaxHistoryItems = @"CustomQueryMaxHistoryItems";
diff --git a/Source/SPDatabaseData.m b/Source/SPDatabaseData.m
index becd1d6e..27b542c4 100644
--- a/Source/SPDatabaseData.m
+++ b/Source/SPDatabaseData.m
@@ -29,6 +29,7 @@
@interface SPDatabaseData (PrivateAPI)
- (NSMutableArray *)_getDatabaseDataForQuery:(NSString *)query;
+NSInteger _sortMySQL4CharsetEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context);
@end
@@ -392,8 +393,21 @@ const SPDatabaseCharSets charsets[] =
// Try to retrieve the available character set encodings from the database
// Check the information_schema.character_sets table is accessible
- if (serverMajorVersion >= 5)
- [characterSetEncodings addObjectsFromArray:[self _getDatabaseDataForQuery:@"SELECT * FROM `information_schema`.`character_sets` ORDER BY `character_set_name` ASC"]];
+ if (serverMajorVersion >= 5) {
+ [characterSetEncodings addObjectsFromArray:[self _getDatabaseDataForQuery:@"SELECT * FROM `information_schema`.`character_sets` ORDER BY `character_set_name` ASC"]];
+ } else if (serverMajorVersion == 4 && serverMinorVersion >= 1) {
+ NSArray *supportedEncodings = [self _getDatabaseDataForQuery:@"SHOW CHARACTER SET"];
+ supportedEncodings = [supportedEncodings sortedArrayUsingFunction:_sortMySQL4CharsetEntry context:nil];
+ for (NSDictionary *anEncoding in supportedEncodings) {
+ NSDictionary *convertedEncoding = [NSDictionary dictionaryWithObjectsAndKeys:
+ [anEncoding objectForKey:@"Charset"], @"CHARACTER_SET_NAME",
+ [anEncoding objectForKey:@"Description"], @"DESCRIPTION",
+ [anEncoding objectForKey:@"Default collation"], @"DEFAULT_COLLATE_NAME",
+ [anEncoding objectForKey:@"Maxlen"], @"MAXLEN",
+ nil];
+ [characterSetEncodings addObject:convertedEncoding];
+ }
+ }
// If that failed, get the list of character set encodings from the hard-coded list
if (![characterSetEncodings count]) {
@@ -453,4 +467,12 @@ const SPDatabaseCharSets charsets[] =
return array;
}
+/**
+ * Sorts a 4.1-style SHOW CHARACTER SET result by the Charset key.
+ */
+NSInteger _sortMySQL4CharsetEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context)
+{
+ return [[itemOne objectForKey:@"Charset"] compare:[itemTwo objectForKey:@"Charset"]];
+}
+
@end
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h
index 315b231c..3ca3ad6f 100644
--- a/Source/SPDatabaseDocument.h
+++ b/Source/SPDatabaseDocument.h
@@ -239,9 +239,9 @@
- (BOOL)connectionEncodingViaLatin1:(id)connection;
- (IBAction)chooseEncoding:(id)sender;
- (BOOL)supportsEncoding;
-- (void)updateEncodingMenuWithSelectedEncoding:(NSString *)encoding;
-- (NSString *)encodingNameFromMySQLEncoding:(NSString *)mysqlEncoding;
-- (NSString *)mysqlEncodingFromDisplayEncoding:(NSString *)encodingName;
+- (void)updateEncodingMenuWithSelectedEncoding:(NSNumber *)encodingTag;
+- (NSNumber *)encodingTagFromMySQLEncoding:(NSString *)mysqlEncoding;
+- (NSString *)mysqlEncodingFromEncodingTag:(NSNumber *)encodingTag;
// Table methods
- (IBAction)showCreateTableSyntax:(id)sender;
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index e06065af..c5381114 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -636,11 +636,11 @@
if ([self isUntitled]) [[parentWindow standardWindowButton:NSWindowDocumentIconButton] setImage:nil];
// Set the connection encoding
- NSString *encodingName = [prefs objectForKey:SPDefaultEncoding];
- if ( [encodingName isEqualToString:@"Autodetect"] ) {
+ NSNumber *encodingType = [prefs objectForKey:SPDefaultEncoding];
+ if ( [encodingType intValue] == SPEncodingAutodetect ) {
[self setConnectionEncoding:[self databaseEncoding] reloadingViews:NO];
} else {
- [self setConnectionEncoding:[self mysqlEncodingFromDisplayEncoding:encodingName] reloadingViews:NO];
+ [self setConnectionEncoding:[self mysqlEncodingFromEncodingTag:encodingType] reloadingViews:NO];
}
// Get the mysql version
@@ -888,6 +888,36 @@
if (![tablesListInstance selectionShouldChangeInTableView:nil]) return;
[databaseNameField setStringValue:@""];
+
+ // Populate the database encoding popup button with a default menu item
+ [databaseEncodingButton removeAllItems];
+ [databaseEncodingButton addItemWithTitle:@"Default"];
+
+ // Retrieve the server-supported encodings and add them to the menu
+ NSArray *encodings = [databaseDataInstance getDatabaseCharacterSetEncodings];
+ NSString *utf8MenuItemTitle = nil;
+ if ([encodings count] > 0
+ && ([mySQLConnection serverMajorVersion] > 4
+ || ([mySQLConnection serverMajorVersion] == 4 && [mySQLConnection serverMinorVersion] >= 1)))
+ {
+ [[databaseEncodingButton menu] addItem:[NSMenuItem separatorItem]];
+ for (NSDictionary *encoding in encodings) {
+ NSString *menuItemTitle = (![encoding objectForKey:@"DESCRIPTION"]) ? [encoding objectForKey:@"CHARACTER_SET_NAME"] : [NSString stringWithFormat:@"%@ (%@)", [encoding objectForKey:@"DESCRIPTION"], [encoding objectForKey:@"CHARACTER_SET_NAME"]];
+ [databaseEncodingButton addItemWithTitle:menuItemTitle];
+
+ // If the UTF8 entry has been encountered, store the title
+ if ([[encoding objectForKey:@"CHARACTER_SET_NAME"] isEqualToString:@"utf8"]) {
+ utf8MenuItemTitle = [NSString stringWithString:menuItemTitle];
+ }
+ }
+
+ // If a UTF8 entry was found, promote it to the top of the list
+ if (utf8MenuItemTitle) {
+ [[databaseEncodingButton menu] insertItem:[NSMenuItem separatorItem] atIndex:2];
+ [databaseEncodingButton insertItemWithTitle:utf8MenuItemTitle atIndex:2];
+ }
+ }
+
[NSApp beginSheet:databaseSheet
modalForWindow:parentWindow
@@ -1495,9 +1525,9 @@
// update the selected menu item
if (_encodingViaLatin1) {
- [self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:[NSString stringWithFormat:@"%@-", mysqlEncoding]]];
+ [self updateEncodingMenuWithSelectedEncoding:[self encodingTagFromMySQLEncoding:[NSString stringWithFormat:@"%@-", mysqlEncoding]]];
} else {
- [self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:mysqlEncoding]];
+ [self updateEncodingMenuWithSelectedEncoding:[self encodingTagFromMySQLEncoding:mysqlEncoding]];
}
// Reload stuff as appropriate
@@ -1531,80 +1561,80 @@
*
* @param NSString *encoding - the title of the menu item which will be selected
*/
-- (void)updateEncodingMenuWithSelectedEncoding:(NSString *)encoding
+- (void)updateEncodingMenuWithSelectedEncoding:(NSNumber *)encodingTag
{
- NSEnumerator *dbEncodingMenuEn = [[selectEncodingMenu itemArray] objectEnumerator];
- id menuItem;
+ NSInteger itemToSelect = [encodingTag integerValue];
NSInteger correctStateForMenuItem;
- while (menuItem = [dbEncodingMenuEn nextObject]) {
- correctStateForMenuItem = [[menuItem title] isEqualToString:encoding] ? NSOnState : NSOffState;
- if ([menuItem state] == correctStateForMenuItem) // don't re-apply state incase it causes performance issues
+ for (NSMenuItem *aMenuItem in [selectEncodingMenu itemArray]) {
+ correctStateForMenuItem = ([aMenuItem tag] == itemToSelect) ? NSOnState : NSOffState;
+
+ if ([aMenuItem state] == correctStateForMenuItem) // don't re-apply state incase it causes performance issues
continue;
- [menuItem setState:correctStateForMenuItem];
+ [aMenuItem setState:correctStateForMenuItem];
}
}
/**
* Returns the display name for a mysql encoding
*/
-- (NSString *)encodingNameFromMySQLEncoding:(NSString *)mysqlEncoding
+- (NSNumber *)encodingTagFromMySQLEncoding:(NSString *)mysqlEncoding
{
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",
- @"Windows Latin 2 (cp1250)", @"cp1250",
- @"ISO Latin 2 (latin2)", @"latin2",
- @"Windows Arabic (cp1256)", @"cp1256",
- @"ISO Greek (greek)", @"greek",
- @"ISO Hebrew (hebrew)", @"hebrew",
- @"ISO Turkish (latin5)", @"latin5",
- @"Windows Baltic (cp1257)", @"cp1257",
- @"Windows Cyrillic (cp1251)", @"cp1251",
- @"Big5 Traditional Chinese (big5)", @"big5",
- @"Shift-JIS Japanese (sjis)", @"sjis",
- @"EUC-JP Japanese (ujis)", @"ujis",
- @"EUC-KR Korean (euckr)", @"euckr",
+ [NSNumber numberWithInt:SPEncodingUCS2], @"ucs2",
+ [NSNumber numberWithInt:SPEncodingUTF8], @"utf8",
+ [NSNumber numberWithInt:SPEncodingUTF8viaLatin1], @"utf8-",
+ [NSNumber numberWithInt:SPEncodingASCII], @"ascii",
+ [NSNumber numberWithInt:SPEncodingLatin1], @"latin1",
+ [NSNumber numberWithInt:SPEncodingMacRoman], @"macroman",
+ [NSNumber numberWithInt:SPEncodingCP1250Latin2], @"cp1250",
+ [NSNumber numberWithInt:SPEncodingISOLatin2], @"latin2",
+ [NSNumber numberWithInt:SPEncodingCP1256Arabic], @"cp1256",
+ [NSNumber numberWithInt:SPEncodingGreek], @"greek",
+ [NSNumber numberWithInt:SPEncodingHebrew], @"hebrew",
+ [NSNumber numberWithInt:SPEncodingLatin5Turkish], @"latin5",
+ [NSNumber numberWithInt:SPEncodingCP1257WinBaltic], @"cp1257",
+ [NSNumber numberWithInt:SPEncodingCP1251WinCyrillic], @"cp1251",
+ [NSNumber numberWithInt:SPEncodingBig5Chinese], @"big5",
+ [NSNumber numberWithInt:SPEncodingShiftJISJapanese], @"sjis",
+ [NSNumber numberWithInt:SPEncodingEUCJPJapanese], @"ujis",
+ [NSNumber numberWithInt:SPEncodingEUCKRKorean], @"euckr",
nil];
- NSString *encodingName = [translationMap valueForKey:mysqlEncoding];
+ NSNumber *encodingTag = [translationMap valueForKey:mysqlEncoding];
- if (!encodingName)
- return [NSString stringWithFormat:@"Unknown Encoding (%@)", mysqlEncoding, nil];
+ if (!encodingTag)
+ return [NSNumber numberWithInt:SPEncodingAutodetect];
- return encodingName;
+ return encodingTag;
}
/**
* Returns the mysql encoding for an encoding string that is displayed to the user
*/
-- (NSString *)mysqlEncodingFromDisplayEncoding:(NSString *)encodingName
+- (NSString *)mysqlEncodingFromEncodingTag:(NSNumber *)encodingTag
{
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)",
- @"cp1250", @"Windows Latin 2 (cp1250)",
- @"latin2", @"ISO Latin 2 (latin2)",
- @"cp1256", @"Windows Arabic (cp1256)",
- @"greek", @"ISO Greek (greek)",
- @"hebrew", @"ISO Hebrew (hebrew)",
- @"latin5", @"ISO Turkish (latin5)",
- @"cp1257", @"Windows Baltic (cp1257)",
- @"cp1251", @"Windows Cyrillic (cp1251)",
- @"big5", @"Big5 Traditional Chinese (big5)",
- @"sjis", @"Shift-JIS Japanese (sjis)",
- @"ujis", @"EUC-JP Japanese (ujis)",
- @"euckr", @"EUC-KR Korean (euckr)",
+ @"ucs2", [NSString stringWithFormat:@"%i", SPEncodingUCS2],
+ @"utf8", [NSString stringWithFormat:@"%i", SPEncodingUTF8],
+ @"utf8-", [NSString stringWithFormat:@"%i", SPEncodingUTF8viaLatin1],
+ @"ascii", [NSString stringWithFormat:@"%i", SPEncodingASCII],
+ @"latin1", [NSString stringWithFormat:@"%i", SPEncodingLatin1],
+ @"macroman", [NSString stringWithFormat:@"%i", SPEncodingMacRoman],
+ @"cp1250", [NSString stringWithFormat:@"%i", SPEncodingCP1250Latin2],
+ @"latin2", [NSString stringWithFormat:@"%i", SPEncodingISOLatin2],
+ @"cp1256", [NSString stringWithFormat:@"%i", SPEncodingCP1256Arabic],
+ @"greek", [NSString stringWithFormat:@"%i", SPEncodingGreek],
+ @"hebrew", [NSString stringWithFormat:@"%i", SPEncodingHebrew],
+ @"latin5", [NSString stringWithFormat:@"%i", SPEncodingLatin5Turkish],
+ @"cp1257", [NSString stringWithFormat:@"%i", SPEncodingCP1257WinBaltic],
+ @"cp1251", [NSString stringWithFormat:@"%i", SPEncodingCP1251WinCyrillic],
+ @"big5", [NSString stringWithFormat:@"%i", SPEncodingBig5Chinese],
+ @"sjis", [NSString stringWithFormat:@"%i", SPEncodingShiftJISJapanese],
+ @"ujis", [NSString stringWithFormat:@"%i", SPEncodingEUCJPJapanese],
+ @"euckr", [NSString stringWithFormat:@"%i", SPEncodingEUCKRKorean],
nil];
- NSString *mysqlEncoding = [translationMap valueForKey:encodingName];
+ NSString *mysqlEncoding = [translationMap valueForKey:[NSString stringWithFormat:@"%i", [encodingTag intValue]]];
if (!mysqlEncoding)
return @"utf8";
@@ -1646,7 +1676,7 @@
*/
- (IBAction)chooseEncoding:(id)sender
{
- [self setConnectionEncoding:[self mysqlEncodingFromDisplayEncoding:[(NSMenuItem *)sender title]] reloadingViews:YES];
+ [self setConnectionEncoding:[self mysqlEncodingFromEncodingTag:[NSNumber numberWithInt:[(NSMenuItem *)sender tag]]] reloadingViews:YES];
}
/**
@@ -4366,7 +4396,7 @@
// If there is an encoding selected other than the default we must specify it in CREATE DATABASE statement
if ([databaseEncodingButton indexOfSelectedItem] > 0) {
- createStatement = [NSString stringWithFormat:@"%@ DEFAULT CHARACTER SET %@", createStatement, [[self mysqlEncodingFromDisplayEncoding:[databaseEncodingButton title]] backtickQuotedString]];
+ createStatement = [NSString stringWithFormat:@"%@ DEFAULT CHARACTER SET %@", createStatement, [[self mysqlEncodingFromEncodingTag:[databaseEncodingButton tag]] backtickQuotedString]];
}
// Create the database
diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m
index 2a621325..bbf5c434 100644
--- a/Source/SPPreferenceController.m
+++ b/Source/SPPreferenceController.m
@@ -309,6 +309,34 @@
[prefs removeObjectForKey:@"SUSendProfileInfo"];
}
+ // For versions prior to 2325 (<0.9.9), convert the old encoding pref string into the new localizable constant
+ if (recordedVersionNumber < 2325 && [prefs objectForKey:@"DefaultEncoding"] && [[prefs objectForKey:@"DefaultEncoding"] isKindOfClass:[NSString class]]) {
+ NSDictionary *encodingMap = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:SPEncodingAutodetect], @"Autodetect",
+ [NSNumber numberWithInt:SPEncodingUCS2], @"UCS-2 Unicode (ucs2)",
+ [NSNumber numberWithInt:SPEncodingUTF8], @"UTF-8 Unicode (utf8)",
+ [NSNumber numberWithInt:SPEncodingUTF8viaLatin1], @"UTF-8 Unicode via Latin 1",
+ [NSNumber numberWithInt:SPEncodingASCII], @"US ASCII (ascii)",
+ [NSNumber numberWithInt:SPEncodingLatin1], @"ISO Latin 1 (latin1)",
+ [NSNumber numberWithInt:SPEncodingMacRoman], @"Mac Roman (macroman)",
+ [NSNumber numberWithInt:SPEncodingCP1250Latin2], @"Windows Latin 2 (cp1250)",
+ [NSNumber numberWithInt:SPEncodingISOLatin2], @"ISO Latin 2 (latin2)",
+ [NSNumber numberWithInt:SPEncodingCP1256Arabic], @"Windows Arabic (cp1256)",
+ [NSNumber numberWithInt:SPEncodingGreek], @"ISO Greek (greek)",
+ [NSNumber numberWithInt:SPEncodingHebrew], @"ISO Hebrew (hebrew)",
+ [NSNumber numberWithInt:SPEncodingLatin5Turkish], @"ISO Turkish (latin5)",
+ [NSNumber numberWithInt:SPEncodingCP1257WinBaltic], @"Windows Baltic (cp1257)",
+ [NSNumber numberWithInt:SPEncodingCP1251WinCyrillic], @"Windows Cyrillic (cp1251)",
+ [NSNumber numberWithInt:SPEncodingBig5Chinese], @"Big5 Traditional Chinese (big5)",
+ [NSNumber numberWithInt:SPEncodingShiftJISJapanese], @"Shift-JIS Japanese (sjis)",
+ [NSNumber numberWithInt:SPEncodingEUCJPJapanese], @"EUC-JP Japanese (ujis)",
+ [NSNumber numberWithInt:SPEncodingEUCKRKorean], @"EUC-KR Korean (euckr)",
+ nil];
+ NSNumber *newMappedValue = [encodingMap valueForKey:[prefs objectForKey:@"DefaultEncoding"]];
+ if (newMappedValue == nil) newMappedValue = [NSNumber numberWithInt:0];
+ [prefs setObject:newMappedValue forKey:@"DefaultEncodingTag"];
+ }
+
// Update the prefs revision
[prefs setObject:[NSNumber numberWithInteger:currentVersionNumber] forKey:SPLastUsedVersion];
}
@@ -989,6 +1017,19 @@
[preferencesWindow endEditingFor:[preferencesWindow firstResponder]];
}
+// -------------------------------------------------------------------------------
+// windowWillResize:toSize:
+// Trap window resize notifications and use them to disable resizing on most tabs
+// - except for the favourites tab.
+// -------------------------------------------------------------------------------
+- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
+{
+ if ([sender showsResizeIndicator])
+ return frameSize;
+ else
+ return [sender frame].size;
+}
+
#pragma mark -
#pragma mark Other
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 498a5166..509e3b83 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -287,6 +287,35 @@
[tableTypeButton addItemWithTitle:[engine objectForKey:@"Engine"]];
}
+ // Populate the table encoding popup button with a default menu item
+ [tableEncodingButton removeAllItems];
+ [tableEncodingButton addItemWithTitle:@"Default"];
+
+ // Retrieve the server-supported encodings and add them to the menu
+ NSArray *encodings = [databaseDataInstance getDatabaseCharacterSetEncodings];
+ NSString *utf8MenuItemTitle = nil;
+ if ([encodings count] > 0
+ && ([mySQLConnection serverMajorVersion] > 4
+ || ([mySQLConnection serverMajorVersion] == 4 && [mySQLConnection serverMinorVersion] >= 1)))
+ {
+ [[tableEncodingButton menu] addItem:[NSMenuItem separatorItem]];
+ for (NSDictionary *encoding in encodings) {
+ NSString *menuItemTitle = (![encoding objectForKey:@"DESCRIPTION"]) ? [encoding objectForKey:@"CHARACTER_SET_NAME"] : [NSString stringWithFormat:@"%@ (%@)", [encoding objectForKey:@"DESCRIPTION"], [encoding objectForKey:@"CHARACTER_SET_NAME"]];
+ [tableEncodingButton addItemWithTitle:menuItemTitle];
+
+ // If the UTF8 entry has been encountered, store the menu title
+ if ([[encoding objectForKey:@"CHARACTER_SET_NAME"] isEqualToString:@"utf8"]) {
+ utf8MenuItemTitle = [NSString stringWithString:menuItemTitle];
+ }
+ }
+
+ // If a UTF8 entry was found, promote it to the top of the list
+ if (utf8MenuItemTitle) {
+ [[tableEncodingButton menu] insertItem:[NSMenuItem separatorItem] atIndex:2];
+ [tableEncodingButton insertItemWithTitle:utf8MenuItemTitle atIndex:2];
+ }
+ }
+
[NSApp beginSheet:tableSheet
modalForWindow:[tableDocumentInstance parentWindow]
modalDelegate:self
@@ -675,7 +704,7 @@
// If encoding is set to Autodetect, update the connection character set encoding
// based on the newly selected table's encoding - but only if it differs from the current encoding.
- if ([[[NSUserDefaults standardUserDefaults] objectForKey:SPDefaultEncoding] isEqualToString:@"Autodetect"]) {
+ if ([[[NSUserDefaults standardUserDefaults] objectForKey:SPDefaultEncoding] intValue] == SPEncodingAutodetect) {
if (tableEncoding != nil && ![tableEncoding isEqualToString:[tableDocumentInstance connectionEncoding]]) {
[tableDocumentInstance setConnectionEncoding:tableEncoding reloadingViews:NO];
[tableDataInstance resetAllData];
@@ -2033,7 +2062,7 @@
// If there is an encoding selected other than the default we must specify it in CREATE TABLE statement
if ([tableEncodingButton indexOfSelectedItem] > 0) {
- charSetStatement = [NSString stringWithFormat:@"DEFAULT CHARACTER SET %@", [[tableDocumentInstance mysqlEncodingFromDisplayEncoding:[tableEncodingButton title]] backtickQuotedString]];
+ charSetStatement = [NSString stringWithFormat:@"DEFAULT CHARACTER SET %@", [[tableDocumentInstance mysqlEncodingFromEncodingTag:[tableEncodingButton tag]] backtickQuotedString]];
}
// If there is a type selected other than the default we must specify it in CREATE TABLE statement