Browse Source

Added keyed and indexed subscript support to FMResultSet- so you can do use the fancy boxed syntax against it (rs[@"foo"] & rs[0]). Thanks to Robert Ryan for the patches!

ccgus 13 years ago
parent
commit
df02dac4d5
5 changed files with 31 additions and 2 deletions
  1. 3 0
      CHANGES_AND_TODO_LIST.txt
  2. 1 0
      CONTRIBUTORS.txt
  3. 3 0
      src/FMResultSet.h
  4. 8 0
      src/FMResultSet.m
  5. 16 2
      src/fmdb.m

+ 3 - 0
CHANGES_AND_TODO_LIST.txt

@@ -3,6 +3,9 @@ Zip, nada, zilch.  Got any ideas?
 
 If you would like to contribute some code- awesome!  I just ask that you make it conform to the coding conventions already set in here, and to add a couple of tests for your new code to fmdb.m.  And of course, the code should be of general use to more than just a couple of folks.  Send your patches to gus@flyingmeat.com.
 
+2012.11.23
+    Added keyed and indexed subscript support to FMResultSet- so you can do use the fancy boxed syntax against it (rs[@"foo"] & rs[0]).  Thanks to Robert Ryan for the patches!
+
 2012.08.08
     Fixed some problems when compiling with ARC against the 10.8 SDK (patch from Geoffrey Foster!).
 

+ 1 - 0
CONTRIBUTORS.txt

@@ -32,5 +32,6 @@ Drarok Ithaqua
 Chris Dolan
 Sriram Patil
 Geoffrey Foster
+Robert Ryan
 
 Aaaaannnd, Gus Mueller (that's me!)

+ 3 - 0
src/FMResultSet.h

@@ -77,6 +77,9 @@
 - (id)objectForColumnName:(NSString*)columnName;
 - (id)objectForColumnIndex:(int)columnIdx;
 
+- (id)objectForKeyedSubscript:(NSString *)columnName;
+- (id)objectAtIndexedSubscript:(int)columnIdx;
+
 /*
 If you are going to use this data after you iterate over the next row, or after you close the
 result set, make sure to make a copy of the data first (or just use dataForColumn:/dataForColumnIndex:)

+ 8 - 0
src/FMResultSet.m

@@ -419,5 +419,13 @@ - (void)setParentDB:(FMDatabase *)newDb {
     _parentDB = newDb;
 }
 
+- (id)objectAtIndexedSubscript:(int)columnIdx {
+    return [self objectForColumnIndex:columnIdx];
+}
+
+- (id)objectForKeyedSubscript:(NSString *)columnName {
+    return [self objectForColumnName:columnName];
+}
+
 
 @end

+ 16 - 2
src/fmdb.m

@@ -85,8 +85,6 @@ int main (int argc, const char * argv[]) {
     [db executeUpdate:@"vacuum"];
     FMDBQuickCheck(![db hadError]);
     
-    exit(0);
-    
     // but of course, I don't bother checking the error codes below.
     // Bad programmer, no cookie.
     
@@ -151,6 +149,22 @@ int main (int argc, const char * argv[]) {
     
     FMDBQuickCheck(![db hasOpenResultSets]);
     
+    
+    
+    rs = [db executeQuery:@"select rowid, a, b, c from test"];
+    while ([rs next]) {
+        
+        FMDBQuickCheck([rs[0] isEqualTo:rs[@"rowid"]]);
+        FMDBQuickCheck([rs[1] isEqualTo:rs[@"a"]]);
+        FMDBQuickCheck([rs[2] isEqualTo:rs[@"b"]]);
+        FMDBQuickCheck([rs[3] isEqualTo:rs[@"c"]]);
+    }
+    [rs close];
+    
+    
+    
+    
+    
     [db executeUpdate:@"create table ull (a integer)"];
     
     [db executeUpdate:@"insert into ull (a) values (?)" , [NSNumber numberWithUnsignedLongLong:ULLONG_MAX]];