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. --- .../PostgresKit/Source/FLXPostgresKitPrivateAPI.h | 3 ++- .../PostgresKit/Source/FLXPostgresTimeInterval.m | 7 +++++- .../Source/FLXPostgresTypeDateTimeHandler.m | 25 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) (limited to 'Frameworks/PostgresKit/Source') diff --git a/Frameworks/PostgresKit/Source/FLXPostgresKitPrivateAPI.h b/Frameworks/PostgresKit/Source/FLXPostgresKitPrivateAPI.h index d78ac063..1a564b91 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresKitPrivateAPI.h +++ b/Frameworks/PostgresKit/Source/FLXPostgresKitPrivateAPI.h @@ -37,7 +37,8 @@ @interface FLXPostgresTimeInterval () -- (id)initWithInterval:(const PGinterval *)interval; ++ (id)intervalWithPGInterval:(PGinterval *)interval; +- (id)initWithInterval:(PGinterval *)interval; @end diff --git a/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.m b/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.m index 7faaad41..5acd7581 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.m +++ b/Frameworks/PostgresKit/Source/FLXPostgresTimeInterval.m @@ -43,7 +43,12 @@ #pragma mark - -- (id)initWithInterval:(const PGinterval *)interval ++ (id)intervalWithPGInterval:(PGinterval *)interval +{ + return [[[FLXPostgresTimeInterval alloc] initWithInterval:interval] autorelease]; +} + +- (id)initWithInterval:(PGinterval *)interval { if ((self = [super init])) { if (interval) { 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