aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPDatabaseData.h5
-rw-r--r--Source/SPDatabaseData.m77
-rw-r--r--Source/SPDatabaseDocument.m24
-rw-r--r--Source/SPTablesList.h6
-rw-r--r--Source/SPTablesList.m5
5 files changed, 79 insertions, 38 deletions
diff --git a/Source/SPDatabaseData.h b/Source/SPDatabaseData.h
index e315ca6a..23f1711a 100644
--- a/Source/SPDatabaseData.h
+++ b/Source/SPDatabaseData.h
@@ -36,6 +36,8 @@
@interface SPDatabaseData : NSObject
{
NSString *characterSetEncoding;
+ NSString *defaultCharacterSetEncoding;
+ NSString *defaultStorageEngine;
NSMutableArray *collations;
NSMutableArray *characterSetCollations;
@@ -64,4 +66,7 @@
- (NSArray *)getDatabaseStorageEngines;
- (NSArray *)getDatabaseCharacterSetEncodings;
+- (NSString *)getDatabaseDefaultCharacterSet;
+- (NSString *)getDatabaseDefaultStorageEngine;
+
@end
diff --git a/Source/SPDatabaseData.m b/Source/SPDatabaseData.m
index cc782b5e..a49248d1 100644
--- a/Source/SPDatabaseData.m
+++ b/Source/SPDatabaseData.m
@@ -28,9 +28,10 @@
#import "SPDatabaseCharacterSets.h"
#import <SPMySQL/SPMySQL.h>
-@interface SPDatabaseData (PrivateAPI)
+@interface SPDatabaseData ()
- (NSArray *)_getDatabaseDataForQuery:(NSString *)query;
+
NSInteger _sortMySQL4CharsetEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context);
NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context);
@@ -51,6 +52,7 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo,
{
if ((self = [super init])) {
characterSetEncoding = nil;
+ defaultCharacterSetEncoding = nil;
collations = [[NSMutableArray alloc] init];
characterSetCollations = [[NSMutableArray alloc] init];
@@ -281,25 +283,48 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo,
return characterSetEncodings;
}
-#pragma mark -
-#pragma mark Other
-
/**
- * Deallocate ivars.
+ * Returns the databases's default character set encoding.
+ *
+ * @return The default encoding as a string
*/
-- (void)dealloc
+- (NSString *)getDatabaseDefaultCharacterSet
{
- if (characterSetEncoding != nil) {
- [characterSetEncoding release], characterSetEncoding = nil;
+ if (!defaultCharacterSetEncoding) {
+ [defaultCharacterSetEncoding release];
+
+ NSString *variable = [serverSupport supportsCharacterSetDatabaseVar] ? @"character_set_database" : @"character_set";
+
+ SPMySQLResult *result = [connection queryString:[NSString stringWithFormat:@"SHOW VARIABLES LIKE %@", [variable tickQuotedString]]];
+
+ [result setReturnDataAsStrings:YES];
+
+ defaultCharacterSetEncoding = [[result getRowAsDictionary] objectForKey:@"Value"];
}
- [collations release], collations = nil;
- [characterSetCollations release], characterSetCollations = nil;
- [storageEngines release], storageEngines = nil;
- [characterSetEncodings release], characterSetEncodings = nil;
- [cachedCollationsByEncoding release], cachedCollationsByEncoding = nil;
+ return defaultCharacterSetEncoding;
+}
+
+/**
+ * Returns the database's default storage engine.
+ *
+ * @return The default storage engine as a string
+ */
+- (NSString *)getDatabaseDefaultStorageEngine
+{
+ if (!defaultStorageEngine) {
+
+ [defaultStorageEngine release];
+
+ // Use 'table_type' variable rather than 'storage_engine' as it's been available since MySQL 3.23.0
+ SPMySQLResult *result = [connection queryString:@"SHOW VARIABLES LIKE 'table_type'"];
+
+ [result setReturnDataAsStrings:YES];
+
+ defaultStorageEngine = [[result getRowAsDictionary] objectForKey:@"Value"];
+ }
- [super dealloc];
+ return defaultStorageEngine;
}
#pragma mark -
@@ -312,9 +337,9 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo,
- (NSArray *)_getDatabaseDataForQuery:(NSString *)query
{
SPMySQLResult *result = [connection queryString:query];
-
+
if ([connection queryErrored]) return [NSArray array];
-
+
[result setReturnDataAsStrings:YES];
return [result getAllRows];
}
@@ -335,4 +360,24 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo,
return [[itemOne objectForKey:@"Engine"] compare:[itemTwo objectForKey:@"Engine"]];
}
+#pragma mark -
+#pragma mark Other
+
+/**
+ * Deallocate ivars.
+ */
+- (void)dealloc
+{
+ if (characterSetEncoding) [characterSetEncoding release], characterSetEncoding = nil;
+ if (defaultCharacterSetEncoding) [defaultCharacterSetEncoding release], defaultCharacterSetEncoding = nil;
+
+ [collations release], collations = nil;
+ [characterSetCollations release], characterSetCollations = nil;
+ [storageEngines release], storageEngines = nil;
+ [characterSetEncodings release], characterSetEncodings = nil;
+ [cachedCollationsByEncoding release], cachedCollationsByEncoding = nil;
+
+ [super dealloc];
+}
+
@end
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index f09a97da..4f4deaca 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -1567,8 +1567,7 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase";
nil];
NSString *mysqlEncoding = [translationMap valueForKey:[NSString stringWithFormat:@"%i", [encodingTag intValue]]];
- if (!mysqlEncoding)
- return @"utf8";
+ if (!mysqlEncoding) return @"utf8";
return mysqlEncoding;
}
@@ -1588,30 +1587,21 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase";
*/
- (void)detectDatabaseEncoding
{
- SPMySQLResult *charSetResult;
- NSString *mysqlEncoding = nil;
-
_supportsEncoding = YES;
- // MySQL >= 4.1
- if ([serverSupport supportsCharacterSetDatabaseVar]) {
- charSetResult = [mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set_database'"];
- [charSetResult setReturnDataAsStrings:YES];
- mysqlEncoding = [[charSetResult getRowAsDictionary] objectForKey:@"Value"];
- }
- // MySQL 4.0 or older -> only default character set possible, cannot choose others using "set names xy"
- else {
- mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] getRowAsDictionary] objectForKey:@"Value"];
- }
+ NSString *mysqlEncoding = [databaseDataInstance getDatabaseDefaultCharacterSet];
[selectedDatabaseEncoding release];
// Fallback or older version? -> set encoding to mysql default encoding latin1
- if ( !mysqlEncoding ) {
+ if (!mysqlEncoding) {
NSLog(@"Error: no character encoding found, mysql version is %@", [self mySQLVersion]);
+
selectedDatabaseEncoding = [[NSString alloc] initWithString:@"latin1"];
+
_supportsEncoding = NO;
- } else {
+ }
+ else {
selectedDatabaseEncoding = [mysqlEncoding retain];
}
}
diff --git a/Source/SPTablesList.h b/Source/SPTablesList.h
index f8043747..368880f0 100644
--- a/Source/SPTablesList.h
+++ b/Source/SPTablesList.h
@@ -44,9 +44,9 @@
<NSTextFieldDelegate>
#endif
{
- IBOutlet SPDatabaseDocument* tableDocumentInstance;
- IBOutlet SPTableStructure* tableSourceInstance;
- IBOutlet SPTableContent* tableContentInstance;
+ IBOutlet SPDatabaseDocument *tableDocumentInstance;
+ IBOutlet SPTableStructure *tableSourceInstance;
+ IBOutlet SPTableContent *tableContentInstance;
#ifndef SP_REFACTOR /* ivars */
IBOutlet id customQueryInstance;
IBOutlet id tableDumpInstance;
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 844505a8..cfb367e9 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -388,7 +388,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
NSArray *engines = [databaseDataInstance getDatabaseStorageEngines];
// Add default menu item
- [tableTypeButton addItemWithTitle:NSLocalizedString(@"Default",@"New Table Sheet : Table Engine Dropdown : Default")];
+ [tableTypeButton addItemWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Default (%@)", @"New Table Sheet : Table Engine Dropdown : Default"), [databaseDataInstance getDatabaseDefaultStorageEngine]]];
[[tableTypeButton menu] addItem:[NSMenuItem separatorItem]];
for (NSDictionary *engine in engines)
@@ -398,7 +398,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
// Populate the table encoding popup button with a default menu item
[tableEncodingButton removeAllItems];
- [tableEncodingButton addItemWithTitle:NSLocalizedString(@"Default",@"New Table Sheet : Table Encoding Dropdown : Default")];
+ [tableEncodingButton addItemWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Default (%@)", @"New Table Sheet : Table Encoding Dropdown : Default"), [tableDocumentInstance databaseEncoding]]];
// Retrieve the server-supported encodings and add them to the menu
NSArray *encodings = [databaseDataInstance getDatabaseCharacterSetEncodings];
@@ -413,6 +413,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
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