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.
 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
 2012.08.08
     Fixed some problems when compiling with ARC against the 10.8 SDK (patch from Geoffrey Foster!).
     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
 Chris Dolan
 Sriram Patil
 Sriram Patil
 Geoffrey Foster
 Geoffrey Foster
+Robert Ryan
 
 
 Aaaaannnd, Gus Mueller (that's me!)
 Aaaaannnd, Gus Mueller (that's me!)

+ 3 - 0
src/FMResultSet.h

@@ -77,6 +77,9 @@
 - (id)objectForColumnName:(NSString*)columnName;
 - (id)objectForColumnName:(NSString*)columnName;
 - (id)objectForColumnIndex:(int)columnIdx;
 - (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
 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:)
 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;
     _parentDB = newDb;
 }
 }
 
 
+- (id)objectAtIndexedSubscript:(int)columnIdx {
+    return [self objectForColumnIndex:columnIdx];
+}
+
+- (id)objectForKeyedSubscript:(NSString *)columnName {
+    return [self objectForColumnName:columnName];
+}
+
 
 
 @end
 @end

+ 16 - 2
src/fmdb.m

@@ -85,8 +85,6 @@ int main (int argc, const char * argv[]) {
     [db executeUpdate:@"vacuum"];
     [db executeUpdate:@"vacuum"];
     FMDBQuickCheck(![db hadError]);
     FMDBQuickCheck(![db hadError]);
     
     
-    exit(0);
-    
     // but of course, I don't bother checking the error codes below.
     // but of course, I don't bother checking the error codes below.
     // Bad programmer, no cookie.
     // Bad programmer, no cookie.
     
     
@@ -151,6 +149,22 @@ int main (int argc, const char * argv[]) {
     
     
     FMDBQuickCheck(![db hasOpenResultSets]);
     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:@"create table ull (a integer)"];
     
     
     [db executeUpdate:@"insert into ull (a) values (?)" , [NSNumber numberWithUnsignedLongLong:ULLONG_MAX]];
     [db executeUpdate:@"insert into ull (a) values (?)" , [NSNumber numberWithUnsignedLongLong:ULLONG_MAX]];