Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

deprecated resultDict, and added resultDictionary (which is now case …

…sensitive)
  • Loading branch information...
commit 347cf12f0064062a9f17892aca8a831e7f149e28 1 parent 5160fc0
@ccgus authored
Showing with 59 additions and 2 deletions.
  1. +9 −1 src/FMResultSet.h
  2. +32 −1 src/FMResultSet.m
  3. +18 −0 src/fmdb.m
View
10 src/FMResultSet.h
@@ -88,7 +88,15 @@ If you don't, you're going to be in a world of hurt when you try and use the dat
- (BOOL)columnIndexIsNull:(int)columnIdx;
- (BOOL)columnIsNull:(NSString*)columnName;
+
+/* Returns a dictionary of the row results mapped to case sensitive keys of the column names. */
+- (NSDictionary*)resultDictionary;
+
+/* Please use resultDictionary instead. Also, beware that resultDictionary is case sensitive! */
+- (NSDictionary*)resultDict __attribute__ ((deprecated));
+
- (void)kvcMagic:(id)object;
-- (NSDictionary *)resultDict;
+
@end
+
View
33 src/FMResultSet.m
@@ -95,7 +95,7 @@ - (void)kvcMagic:(id)object {
}
}
-- (NSDictionary *)resultDict {
+- (NSDictionary*)resultDict {
int num_cols = sqlite3_data_count([_statement statement]);
@@ -122,6 +122,37 @@ - (NSDictionary *)resultDict {
return nil;
}
+
+- (NSDictionary*)resultDictionary {
+
+ int num_cols = sqlite3_data_count([_statement statement]);
+
+ if (num_cols > 0) {
+ NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];
+
+ int columnCount = sqlite3_column_count([_statement statement]);
+
+ int columnIdx = 0;
+ for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
+
+ NSString *columnName = [NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)];
+ id objectValue = [self objectForColumnIndex:columnIdx];
+ [dict setObject:objectValue forKey:columnName];
+ }
+
+ return dict;
+ }
+ else {
+ NSLog(@"Warning: There seem to be no columns in this set.");
+ }
+
+ return nil;
+}
+
+
+
+
+
- (BOOL)next {
int rc;
View
18 src/fmdb.m
@@ -132,6 +132,24 @@ int main (int argc, const char * argv[]) {
FMDBQuickCheck(b == ULLONG_MAX);
}
+
+ // check case sensitive result dictionary.
+ [db executeUpdate:@"create table cs (aRowName integer, bRowName text)"];
+ FMDBQuickCheck(![db hadError]);
+ [db executeUpdate:@"insert into cs (aRowName, bRowName) values (?, ?)" , [NSNumber numberWithBool:1], @"hello"];
+ FMDBQuickCheck(![db hadError]);
+
+ rs = [db executeQuery:@"select * from cs"];
+ while ([rs next]) {
+ NSDictionary *d = [rs resultDictionary];
+
+ FMDBQuickCheck([d objectForKey:@"aRowName"]);
+ FMDBQuickCheck(![d objectForKey:@"arowname"]);
+ FMDBQuickCheck([d objectForKey:@"bRowName"]);
+ FMDBQuickCheck(![d objectForKey:@"browname"]);
+ }
+
+
// ----------------------------------------------------------------------------------------
// blob support.
[db executeUpdate:@"create table blobTable (a text, b blob)"];
Please sign in to comment.
Something went wrong with that request. Please try again.