diff options
author | dmoagx <post@wickenrode.com> | 2013-03-07 19:46:08 +0000 |
---|---|---|
committer | dmoagx <post@wickenrode.com> | 2013-03-07 19:46:08 +0000 |
commit | c51d93d760b6ad47ac4256bdf564688cb9a5d2f8 (patch) | |
tree | 62f2d2793e7a46281d30c5f44218617bfbf4b59e /Source/SPDatabaseData.m | |
parent | 2a7c3296a7186558446d136d4c87633126561371 (diff) | |
download | sequelpro-c51d93d760b6ad47ac4256bdf564688cb9a5d2f8.tar.gz sequelpro-c51d93d760b6ad47ac4256bdf564688cb9a5d2f8.tar.bz2 sequelpro-c51d93d760b6ad47ac4256bdf564688cb9a5d2f8.zip |
* Add support for querying MySQL 4 for collations
Diffstat (limited to 'Source/SPDatabaseData.m')
-rw-r--r-- | Source/SPDatabaseData.m | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Source/SPDatabaseData.m b/Source/SPDatabaseData.m index 202f56ce..835c7328 100644 --- a/Source/SPDatabaseData.m +++ b/Source/SPDatabaseData.m @@ -39,8 +39,10 @@ @interface SPDatabaseData () - (NSArray *)_getDatabaseDataForQuery:(NSString *)query; ++ (NSArray *)_relabelCollationResult:(NSArray *)data; NSInteger _sortMySQL4CharsetEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context); +NSInteger _sortMySQL4CollationEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context); NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context); @end @@ -100,6 +102,14 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo, if ([serverSupport supportsInformationSchema]) { [collations addObjectsFromArray:[self _getDatabaseDataForQuery:@"SELECT * FROM `information_schema`.`collations` ORDER BY `collation_name` ASC"]]; } + else if([serverSupport supportsShowCollation]) { + //use the 4.1-style query + NSArray *supportedCollations = [self _getDatabaseDataForQuery:@"SHOW COLLATION"]; + //apply the sorting + supportedCollations = [supportedCollations sortedArrayUsingFunction:_sortMySQL4CollationEntry context:nil]; + //convert the output to the information_schema style + [collations addObjectsFromArray:[SPDatabaseData _relabelCollationResult:supportedCollations]]; + } // If that failed, get the list of collations from the hard-coded list if (![collations count]) { @@ -137,6 +147,14 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo, if ([serverSupport supportsInformationSchema]) { [characterSetCollations addObjectsFromArray:[self _getDatabaseDataForQuery:[NSString stringWithFormat:@"SELECT * FROM `information_schema`.`collations` WHERE character_set_name = '%@' ORDER BY `collation_name` ASC", characterSetEncoding]]]; } + else if([serverSupport supportsShowCollation]) { + //use the 4.1-style query (as every collation name starts with the charset name we can use the prefix search) + NSArray *supportedCollations = [self _getDatabaseDataForQuery:[NSString stringWithFormat:@"SHOW COLLATION LIKE '%@%%'",characterSetEncoding]]; + //apply the sorting + supportedCollations = [supportedCollations sortedArrayUsingFunction:_sortMySQL4CollationEntry context:nil]; + + [characterSetCollations addObjectsFromArray:[SPDatabaseData _relabelCollationResult:supportedCollations]]; + } // If that failed, get the list of collations matching the supplied encoding from the hard-coded list if (![characterSetCollations count]) { @@ -386,6 +404,29 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo, } /** + * Converts the output of a MySQL 4.1 style "SHOW COLLATION" to the format of a MySQL 5.0 style "SELECT * FROM information_schema.collations" + */ ++ (NSArray *)_relabelCollationResult:(NSArray *)data +{ + NSMutableArray *outData = [[NSMutableArray alloc] initWithCapacity:[data count]]; + + for (NSDictionary *aCollation in data) + { + NSDictionary *convertedCollation = [NSDictionary dictionaryWithObjectsAndKeys: + [aCollation objectForKey:@"Collation"], @"COLLATION_NAME", + [aCollation objectForKey:@"Charset"], @"CHARACTER_SET_NAME", + [aCollation objectForKey:@"Id"], @"ID", + [aCollation objectForKey:@"Default"], @"IS_DEFAULT", + [aCollation objectForKey:@"Compiled"], @"IS_COMPILED", + [aCollation objectForKey:@"Sortlen"], @"SORTLEN", + nil]; + + [outData addObject:convertedCollation]; + } + return [outData autorelease]; +} + +/** * Sorts a 4.1-style SHOW CHARACTER SET result by the Charset key. */ NSInteger _sortMySQL4CharsetEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context) @@ -394,6 +435,14 @@ NSInteger _sortMySQL4CharsetEntry(NSDictionary *itemOne, NSDictionary *itemTwo, } /** + * Sorts a 4.1-style SHOW COLLATION result by the Collation key. + */ +NSInteger _sortMySQL4CollationEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context) +{ + return [[itemOne objectForKey:@"Collation"] compare:[itemTwo objectForKey:@"Collation"]]; +} + +/** * Sorts a storage engine array by the Engine key. */ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo, void *context) |