Convert types using the result of PQftypes().
FossilOrigin-Name: 4a2b1fff7ecbdccaaff50842a27a4921f3e336546b07e9b6ebeb440adb29ef60
This commit is contained in:
parent
728b3d1e2a
commit
d22558fdcc
4 changed files with 46 additions and 9 deletions
|
@ -1,5 +1,25 @@
|
|||
#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;
|
||||
|
@ -67,7 +87,8 @@
|
|||
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
|
||||
|
@ -133,6 +154,7 @@
|
|||
if (pos >= count)
|
||||
return nil;
|
||||
|
||||
return [OFString stringWithUTF8String: PQgetvalue(res, row, pos++)];
|
||||
return convert_type(res, pos,
|
||||
[OFString stringWithUTF8String: PQgetvalue(res, row, pos++)]);
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue