Index: PGResultRow.m ================================================================== --- PGResultRow.m +++ PGResultRow.m @@ -44,11 +44,17 @@ [super dealloc]; } - (size_t)count { - return PQnfields(res); + size_t i, count, fields = PQnfields(res); + + for (i = count = 0; i < fields; i++) + if (!PQgetisnull(res, row, i)) + count++; + + return count; } - (id)objectForKey: (id)key { int col; @@ -55,10 +61,13 @@ if ([key isKindOfClass: [OFNumber class]]) col = [key intValue]; else col = PQfnumber(res, [key UTF8String]); + + if (PQgetisnull(res, row, col)) + return nil; return [OFString stringWithUTF8String: PQgetvalue(res, row, col)]; } - (OFEnumerator*)keyEnumerator @@ -99,19 +108,31 @@ @implementation PGResultRowKeyEnumerator - (id)nextObject { if (pos >= count) return nil; + + while (pos < count && PQgetisnull(res, row, pos)) + pos++; + + if (pos >= count) + return nil; return [OFString stringWithUTF8String: PQfname(res, pos++)]; } @end @implementation PGResultRowObjectEnumerator - (id)nextObject { + if (pos >= count) + return nil; + + while (pos < count && PQgetisnull(res, row, pos)) + pos++; + if (pos >= count) return nil; return [OFString stringWithUTF8String: PQgetvalue(res, row, pos++)]; } @end Index: test.m ================================================================== --- test.m +++ test.m @@ -29,13 +29,13 @@ @" content text" @")"]; [connection executeCommand: @"INSERT INTO test (id, name, content) " @"VALUES($1, $2, $3)" parameters: @[@"1", @"foo", @"Hallo Welt!"]]; - [connection executeCommand: @"INSERT INTO test (id, name, content) " - @"VALUES($1, $2, $3)" - parameters: @[@"2", @"bla", @"Blup!!"]]; + [connection executeCommand: @"INSERT INTO test (id, content) " + @"VALUES($1, $2)" + parameters: @[@"2", @"Blup!!"]]; result = [connection executeCommand: @"SELECT * FROM test"]; of_log(@"%@", result); of_log(@"JSON: %@", [result JSONRepresentation]);