diff options
author | stuconnolly <stuart02@gmail.com> | 2012-09-24 12:23:27 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-09-24 12:23:27 +0000 |
commit | 4e12b294d3fc6eb32c0050047d285fff29320607 (patch) | |
tree | 356af30418b5984aad9e7038d91bfc695fcc8d40 /Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m | |
parent | 4004ca9491c5a4b49b97440aa36f6f1070488b0e (diff) | |
download | sequelpro-4e12b294d3fc6eb32c0050047d285fff29320607.tar.gz sequelpro-4e12b294d3fc6eb32c0050047d285fff29320607.tar.bz2 sequelpro-4e12b294d3fc6eb32c0050047d285fff29320607.zip |
Fix the handling of numeric values.
Diffstat (limited to 'Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m')
-rw-r--r-- | Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m | 30 |
1 files changed, 30 insertions, 0 deletions
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 |