@@ -1,6 +1,26 @@ #import "PGResultRow.h" + +static id +convert_type(PGresult *res, int col, OFString *str) +{ + switch (PQftype(res, col)) { + case 16: /* BOOLOID */ + if ([str isEqual: @"t"]) + return [OFNumber numberWithBool: YES]; + else + return [OFNumber numberWithBool: NO]; + case 21: /* INT2OID */ + return [OFNumber numberWithInt16: (int16_t)[str decimalValue]]; + case 23: /* INT4OID */ + return [OFNumber numberWithInt32: (int32_t)[str decimalValue]]; + case 20: /* INT8OID */ + return [OFNumber numberWithInt64: (int64_t)[str decimalValue]]; + } + + return str; +} @interface PGResultRowEnumerator: OFEnumerator { PGResult *result; PGresult *res; @@ -65,11 +85,12 @@ col = PQfnumber(res, [key UTF8String]); if (PQgetisnull(res, row, col)) return nil; - return [OFString stringWithUTF8String: PQgetvalue(res, row, col)]; + return convert_type(res, col, + [OFString stringWithUTF8String: PQgetvalue(res, row, col)]); } - (OFEnumerator*)keyEnumerator { return [[[PGResultRowKeyEnumerator alloc] @@ -131,8 +152,9 @@ pos++; if (pos >= count) return nil; - return [OFString stringWithUTF8String: PQgetvalue(res, row, pos++)]; + return convert_type(res, pos, + [OFString stringWithUTF8String: PQgetvalue(res, row, pos++)]); } @end