aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m')
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresTypeNumberHandler.m30
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