diff options
author | stuconnolly <stuart02@gmail.com> | 2012-06-10 09:25:14 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-06-10 09:25:14 +0000 |
commit | e4afd6305a2e4a5f57987c4aa7938d2ba20f5676 (patch) | |
tree | 87cfe84c9df5d562b74e0b474d2c153287a98f1c /Source/SPDatabaseData.m | |
parent | 638dcc0e4bc3038224e9921547f4c00a36837f56 (diff) | |
download | sequelpro-e4afd6305a2e4a5f57987c4aa7938d2ba20f5676.tar.gz sequelpro-e4afd6305a2e4a5f57987c4aa7938d2ba20f5676.tar.bz2 sequelpro-e4afd6305a2e4a5f57987c4aa7938d2ba20f5676.zip |
Add the default encoding and storage engine to the default menu items on the new table sheet. Implements issue #1245.
Diffstat (limited to 'Source/SPDatabaseData.m')
-rw-r--r-- | Source/SPDatabaseData.m | 77 |
1 files changed, 61 insertions, 16 deletions
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 |