aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPDatabaseData.h1
-rw-r--r--Source/SPDatabaseData.m45
2 files changed, 33 insertions, 13 deletions
diff --git a/Source/SPDatabaseData.h b/Source/SPDatabaseData.h
index f2fe08e1..cdc44fa3 100644
--- a/Source/SPDatabaseData.h
+++ b/Source/SPDatabaseData.h
@@ -74,6 +74,7 @@
- (NSArray *)getDatabaseCollations;
- (NSArray *)getDatabaseCollationsForEncoding:(NSString *)encoding;
- (NSString *)getDefaultCollationForEncoding:(NSString *)encoding;
+- (NSString *)getEncodingFromCollation:(NSString *)collation;
- (NSArray *)getDatabaseStorageEngines;
- (NSArray *)getDatabaseCharacterSetEncodings;
diff --git a/Source/SPDatabaseData.m b/Source/SPDatabaseData.m
index 2d1d4f14..0cbb756a 100644
--- a/Source/SPDatabaseData.m
+++ b/Source/SPDatabaseData.m
@@ -130,7 +130,7 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo,
++c;
}
- while (c[0].nr != 0);
+ while (c->nr != 0);
}
}
@@ -180,12 +180,14 @@ NSInteger _sortStorageEngineEntry(NSDictionary *itemOne, NSDictionary *itemTwo,
NSString *charSet = [NSString stringWithCString:c->name encoding:NSUTF8StringEncoding];
if ([charSet isEqualToString:characterSetEncoding]) {
- [characterSetCollations addObject:@{@"COLLATION_NAME" : [NSString stringWithCString:c->collation encoding:NSUTF8StringEncoding]}];
+ [characterSetCollations addObject:@{
+ @"COLLATION_NAME" : [NSString stringWithCString:c->collation encoding:NSUTF8StringEncoding]
+ }];
}
++c;
}
- while (c[0].nr != 0);
+ while (c->nr != 0);
}
if ([characterSetCollations count]) {
@@ -222,6 +224,23 @@ copy_return:
return defaultCollationForCharacterSet;
}
+/** Get the name of the mysql charset a given collation belongs to.
+ * @param collation Name of the collation (e.g. "latin1_swedish_ci")
+ * @return name of the charset (e.g. "latin1") or nil if unknown
+ *
+ * According to the MySQL doc every collation can only ever belong to a single charset.
+ */
+- (NSString *)getEncodingFromCollation:(NSString *)collation {
+ if([collation length]) { //shortcut for nil and @""
+ for(NSDictionary *coll in [self getDatabaseCollations]) {
+ if([[coll objectForKey:@"COLLATION_NAME"] isEqualToString:collation]) {
+ return [coll objectForKey:@"CHARACTER_SET_NAME"];
+ }
+ }
+ }
+ return nil;
+}
+
/**
* Returns all of the database's available storage engines.
*/
@@ -321,11 +340,11 @@ copy_return:
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];
+ [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];
}
@@ -336,14 +355,14 @@ copy_return:
const SPDatabaseCharSets *c = SPGetDatabaseCharacterSets();
#warning This probably won't work as intended. See my comment in getDatabaseCollationsForEncoding:
do {
- [characterSetEncodings addObject:[NSDictionary dictionaryWithObjectsAndKeys:
- [NSString stringWithCString:c->name encoding:NSUTF8StringEncoding], @"CHARACTER_SET_NAME",
- [NSString stringWithCString:c->description encoding:NSUTF8StringEncoding], @"DESCRIPTION",
- nil]];
+ [characterSetEncodings addObject:@{
+ @"CHARACTER_SET_NAME" : [NSString stringWithCString:c->name encoding:NSUTF8StringEncoding],
+ @"DESCRIPTION" : [NSString stringWithCString:c->description encoding:NSUTF8StringEncoding]
+ }];
++c;
}
- while (c[0].nr != 0);
+ while (c->nr != 0);
}
}