From 6ac4ca07b1b0d61d718e73e0ba35a579ccc162c7 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 9 Sep 2012 01:10:06 +0000 Subject: Hook up time interval support. --- .../Source/FLXPostgresTypeDateTimeHandler.m | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m') diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m b/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m index b28868cc..2dd4227c 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m +++ b/Frameworks/PostgresKit/Source/FLXPostgresTypeDateTimeHandler.m @@ -26,6 +26,8 @@ #import "FLXPostgresConnection.h" #import "FLXPostgresConnectionTypeHandling.h" #import "FLXPostgresTimeTZ.h" +#import "FLXPostgresTimeInterval.h" +#import "FLXPostgresKitPrivateAPI.h" static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] = { @@ -35,12 +37,15 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] = FLXPostgresOidAbsTime, FLXPostgresOidTimestamp, FLXPostgresOidTimestampTZ, + FLXPostgresOidInterval, 0 }; @interface FLXPostgresTypeDateTimeHandler () - (NSDate *)_dateFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column; +- (FLXPostgresTimeInterval *)_timeIntervalFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column; + - (id)_timeFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type; - (id)_timestmpFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column type:(FLXPostgresOid)type; @@ -83,6 +88,8 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] = case FLXPostgresOidTimestamp: case FLXPostgresOidTimestampTZ: return [self _timestmpFromResult:result atRow:row column:column type:type]; + case FLXPostgresOidInterval: + return [self _timeIntervalFromResult:result atRow:row column:column]; default: return nil; } @@ -115,6 +122,24 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] = return [self _dateFromComponents:components]; } +/** + * Converts a time interval value to a FLXPostgresTimeInterval instance. + * + * @param result The result to extract the value from. + * @param row The row to extract the value from. + * @param column The column to extract the value from. + * + * @return The FLXPostgresTimeInterval representation. + */ +- (FLXPostgresTimeInterval *)_timeIntervalFromResult:(const PGresult *)result atRow:(NSUInteger)row column:(NSUInteger)column +{ + PGinterval interval; + + if (!PQgetf(result, row, "%interval", column, &interval)) return nil; + + return [FLXPostgresTimeInterval intervalWithPGInterval:&interval]; +} + /** * Returns a native object created from a time value. * -- cgit v1.2.3