Index: src/SL3PreparedStatement.h ================================================================== --- src/SL3PreparedStatement.h +++ src/SL3PreparedStatement.h @@ -39,13 +39,15 @@ - (void)bindWithArray: (OFArray *)array; - (void)bindWithDictionary: (OFDictionary OF_GENERIC(OFString *, id) *)dictionary; - (void)clearBindings; +- (bool)step; - (id)objectForColumn: (size_t)column; - (size_t)columnCount; - (OFString *)nameForColumn: (size_t)column; -- (bool)step; +- (OFArray *)rowArray; +- (OFDictionary OF_GENERIC(OFString *, id) *)rowDictionary; - (void)reset; @end OF_ASSUME_NONNULL_END Index: src/SL3PreparedStatement.m ================================================================== --- src/SL3PreparedStatement.m +++ src/SL3PreparedStatement.m @@ -214,10 +214,38 @@ if ((name = sqlite3_column_name(_stmt, column)) == NULL) @throw [OFOutOfMemoryException exception]; return [OFString stringWithUTF8String: name]; } + +- (OFArray *)rowArray +{ + size_t count = [self columnCount]; + OFMutableArray *array = [OFMutableArray arrayWithCapacity: count]; + + for (size_t i = 0; i < count; i++) + [array addObject: [self objectForColumn: i]]; + + [array makeImmutable]; + + return array; +} + +- (OFDictionary OF_GENERIC(OFString *, id) *)rowDictionary +{ + size_t count = [self columnCount]; + OFMutableDictionary *dictionary = + [OFMutableDictionary dictionaryWithCapacity: count]; + + for (size_t i = 0; i < count; i++) + [dictionary setObject: [self objectForColumn: i] + forKey: [self nameForColumn: i]]; + + [dictionary makeImmutable]; + + return dictionary; +} - (void)reset { int code = sqlite3_reset(_stmt); Index: tests/Tests.m ================================================================== --- tests/Tests.m +++ tests/Tests.m @@ -64,37 +64,45 @@ nil]]; [stmt step]; stmt = [conn prepareStatement: @"SELECT * FROM test"]; for (size_t i = 0; [stmt step]; i++) { + OFNumber *a; + OFString *b; + OFData *c; + OF_ENSURE([stmt columnCount] == 3); OF_ENSURE([[stmt nameForColumn: 0] isEqual: @"a"]); OF_ENSURE([[stmt nameForColumn: 1] isEqual: @"b"]); OF_ENSURE([[stmt nameForColumn: 2] isEqual: @"c"]); switch (i) { case 0: - OF_ENSURE([[stmt objectForColumn: 0] - isEqual: [OFNumber numberWithInt: 5]]); - OF_ENSURE([[stmt objectForColumn: 1] - isEqual: @"String"]); - OF_ENSURE([[stmt objectForColumn: 2] - isEqual: [OFData dataWithItems: "abc" - count: 3]]); + a = [OFNumber numberWithInt: 5]; + b = @"String"; + c = [OFData dataWithItems: "abc" + count: 3]; break; case 1: - OF_ENSURE([[stmt objectForColumn: 0] - isEqual: [OFNumber numberWithInt: 7]]); - OF_ENSURE([[stmt objectForColumn: 1] - isEqual: @"Test"]); - OF_ENSURE([[stmt objectForColumn: 2] - isEqual: [OFData dataWithItems: "xyz" - count: 3]]); + a = [OFNumber numberWithInt: 7]; + b = @"Test"; + c = [OFData dataWithItems: "xyz" + count: 3]; break; default: OF_ENSURE(0); } + + OF_ENSURE([[stmt objectForColumn: 0] isEqual: a]); + OF_ENSURE([[stmt objectForColumn: 1] isEqual: b]); + OF_ENSURE([[stmt objectForColumn: 2] isEqual: c]); + + OF_ENSURE([[stmt rowArray] isEqual: ([OFArray arrayWithObjects: + a, b, c, nil])]); + OF_ENSURE([[stmt rowDictionary] isEqual: + ([OFDictionary dictionaryWithKeysAndObjects: + @"a", a, @"b", b, @"c", c, nil])]); } [OFApplication terminate]; } @end