diff options
Diffstat (limited to 'Frameworks/PostgresKit')
5 files changed, 33 insertions, 3 deletions
diff --git a/Frameworks/PostgresKit/Source/FLXConstants.h b/Frameworks/PostgresKit/Source/FLXConstants.h index b14ba5c1..bea01ff2 100644 --- a/Frameworks/PostgresKit/Source/FLXConstants.h +++ b/Frameworks/PostgresKit/Source/FLXConstants.h @@ -46,6 +46,7 @@ extern const char *FLXPostgresResultValueTimeTZ; extern const char *FLXPostgresResultValueTimestamp; extern const char *FLXPostgresResultValueTimestmpTZ; extern const char *FLXPostgresResultValueInterval; +extern const char *FLXPostgresResultValueNumeric; // Connection parameters extern const char *FLXPostgresKitApplicationName; diff --git a/Frameworks/PostgresKit/Source/FLXConstants.m b/Frameworks/PostgresKit/Source/FLXConstants.m index 4f82bef8..c376a493 100644 --- a/Frameworks/PostgresKit/Source/FLXConstants.m +++ b/Frameworks/PostgresKit/Source/FLXConstants.m @@ -46,6 +46,7 @@ const char *FLXPostgresResultValueTimeTZ = "%timetz"; const char *FLXPostgresResultValueTimestamp = "%timestamp"; const char *FLXPostgresResultValueTimestmpTZ = "%timestamptz"; const char *FLXPostgresResultValueInterval = "%interval"; +const char *FLXPostgresResultValueNumeric = "%numeric"; // Connection parameters const char *FLXPostgresKitApplicationName = "PostgresKit"; diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m index 8063a960..00a3f781 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m +++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m @@ -32,6 +32,7 @@ static FLXPostgresOid FLXPostgresTypeNumberTypes[] = FLXPostgresOidBool, FLXPostgresOidOid, FLXPostgresOidMoney, + FLXPostgresOidNumeric, 0 }; @@ -48,6 +49,8 @@ static FLXPostgresOid FLXPostgresTypeNumberTypes[] = - (id)_floatObjectFromBytes:(const void *)bytes length:(NSUInteger)length; - (id)_booleanObjectFromBytes:(const void *)bytes length:(NSUInteger)length; +- (id)_numericFromResult; + @end @implementation FLXPostgresTypeNumberHandler @@ -95,6 +98,8 @@ static FLXPostgresOid FLXPostgresTypeNumberTypes[] = return [self _floatObjectFromBytes:bytes length:length]; case FLXPostgresOidBool: return [self _booleanObjectFromBytes:bytes length:length]; + case FLXPostgresOidNumeric: + return [self _numericFromResult]; default: return [NSNull null]; } @@ -179,4 +184,29 @@ static FLXPostgresOid FLXPostgresTypeNumberTypes[] = return [NSNumber numberWithBool:*((const int8_t *)bytes) ? YES : NO]; } +#pragma mark - +#pragma mark Numeric + +/** + * Converts a numeric value to a native NSNumber instance. + * + * @return An NSNumber representation of the the value. + */ +- (id)_numericFromResult +{ + PGnumeric numeric; + + if (!PQgetf(_result, (int)_row, FLXPostgresResultValueNumeric, (int)_column, &numeric)) return [NSNull null]; + + NSString *stringValue = [[NSString alloc] initWithUTF8String:numeric]; + + double value = [stringValue doubleValue]; + + if (value == HUGE_VAL || value == -HUGE_VAL) return [NSNull null]; + + [stringValue release]; + + return [NSNumber numberWithDouble:value]; +} + @end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m index cdb2ea94..68c9a45e 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m +++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeStringHandler.m @@ -30,7 +30,6 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] = FLXPostgresOidText, FLXPostgresOidChar, FLXPostgresOidName, - FLXPostgresOidNumeric, FLXPostgresOidVarChar, FLXPostgresOidXML, FLXPostgresOidUUID, @@ -85,7 +84,6 @@ static FLXPostgresOid FLXPostgresTypeStringTypes[] = case FLXPostgresOidText: case FLXPostgresOidChar: case FLXPostgresOidName: - case FLXPostgresOidNumeric: case FLXPostgresOidVarChar: case FLXPostgresOidXML: case FLXPostgresOidUUID: diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypes.h b/Frameworks/PostgresKit/Source/FLXPostgresTypes.h index 0a382950..9f923552 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypes.h +++ b/Frameworks/PostgresKit/Source/FLXPostgresTypes.h @@ -112,7 +112,7 @@ enum FLXPostgresOidVarBit = 1562, // StringHandler => NSString // Numeric - FLXPostgresOidNumeric = 1700, // StringHandler => NSString + FLXPostgresOidNumeric = 1700, // NumberHandler => NSNumber // UUID FLXPostgresOidUUID = 2950 // StringHandler => NSString |