瀏覽代碼

deprecated resultDict, and added resultDictionary (which is now case sensitive)

August Mueller 13 年之前
父節點
當前提交
347cf12f00
共有 3 個文件被更改,包括 59 次插入2 次删除
  1. 9 1
      src/FMResultSet.h
  2. 32 1
      src/FMResultSet.m
  3. 18 0
      src/fmdb.m

+ 9 - 1
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
+

+ 32 - 1
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;

+ 18 - 0
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)"];