From d01fe26b1e1965d81c6971a48a6b7856aa821cbf Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Fri, 28 Sep 2012 09:07:30 +0000 Subject: Tidy up binary handler. --- .../Source/PGPostgresTypeBinaryHandler.m | 32 ++-------------------- Frameworks/PostgresKit/Source/PGPostgresTypes.h | 3 +- 2 files changed, 4 insertions(+), 31 deletions(-) (limited to 'Frameworks/PostgresKit/Source') diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.m b/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.m index f544fb39..6c40ca14 100644 --- a/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.m +++ b/Frameworks/PostgresKit/Source/PGPostgresTypeBinaryHandler.m @@ -36,13 +36,6 @@ static PGPostgresOid PGPostgresTypeBinaryTypes[] = 0 }; -@interface PGPostgresTypeBinaryHandler () - -- (id)_binaryDataFromResult; - -@end - - @implementation PGPostgresTypeBinaryHandler @synthesize row = _row; @@ -70,32 +63,13 @@ static PGPostgresOid PGPostgresTypeBinaryTypes[] = - (id)objectFromResult { - if (!_result || !_type) return [NSNull null]; - - switch (_type) - { - case PGPostgresOidByteData: - return [self _binaryDataFromResult]; - } - - return [NSNull null]; -} - -#pragma mark - -#pragma mark Private API - -/** - * Converts a binary data value to an NSData instance. - * - * @return The NSData representation of the data. - */ -- (id)_binaryDataFromResult -{ PGbytea data; + if (!_result || !_type) return [NSNull null]; + if (!PQgetf(_result, _row, PGPostgresResultValueByteA, _column)) return [NSNull null]; - if (!data.data || !data.len) return [NSNull null]; + if (!data.data || !data.len) return [NSData data]; return [NSData dataWithBytes:data.data length:data.len]; } diff --git a/Frameworks/PostgresKit/Source/PGPostgresTypes.h b/Frameworks/PostgresKit/Source/PGPostgresTypes.h index 993e824d..c5812c4e 100644 --- a/Frameworks/PostgresKit/Source/PGPostgresTypes.h +++ b/Frameworks/PostgresKit/Source/PGPostgresTypes.h @@ -26,12 +26,11 @@ typedef Oid PGPostgresOid; // See PostgreSQL source: include/catalog/pg_type.h - enum { // BOOL PGPostgresOidBool = 16, // NumberHandler => NSNumber - PGPostgresOidByteData = 17, // Currently not supported + PGPostgresOidByteData = 17, // BinaryHandler => NSData // Text PGPostgresOidName = 19, // StringHandler => NSString -- cgit v1.2.3