diff options
author | stuconnolly <stuart02@gmail.com> | 2012-09-09 01:10:06 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-09-09 01:10:06 +0000 |
commit | 6ac4ca07b1b0d61d718e73e0ba35a579ccc162c7 (patch) | |
tree | 5c2b21db911d0f80dda3c4a2fc23af35fb8a766e /Frameworks/PostgresKit | |
parent | 44ca403e94e748cbf1db6941aece22029c77c542 (diff) | |
download | sequelpro-6ac4ca07b1b0d61d718e73e0ba35a579ccc162c7.tar.gz sequelpro-6ac4ca07b1b0d61d718e73e0ba35a579ccc162c7.tar.bz2 sequelpro-6ac4ca07b1b0d61d718e73e0ba35a579ccc162c7.zip |
Hook up time interval support.
Diffstat (limited to 'Frameworks/PostgresKit')
3 files changed, 33 insertions, 2 deletions
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; } @@ -116,6 +123,24 @@ static FLXPostgresOid FLXPostgresTypeDateTimeTypes[] = } /** + * 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. * * @note The date part should be ignored as it's set to a default value. |