From a0b76fba5ade5b1c018cb7ebcfae193cec114f5f Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 16 Sep 2012 04:27:12 +0000 Subject: Add the ability to set the default row return type. --- Frameworks/PostgresKit/Source/FLXPostgresResult.h | 9 ++++++++- Frameworks/PostgresKit/Source/FLXPostgresResult.m | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'Frameworks/PostgresKit/Source') diff --git a/Frameworks/PostgresKit/Source/FLXPostgresResult.h b/Frameworks/PostgresKit/Source/FLXPostgresResult.h index 4148ba3d..168f8f15 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresResult.h +++ b/Frameworks/PostgresKit/Source/FLXPostgresResult.h @@ -30,7 +30,7 @@ typedef enum } FLXPostgresResultRowType; -@interface FLXPostgresResult : NSObject +@interface FLXPostgresResult : NSObject { void *_result; void **_typeHandlers; @@ -43,6 +43,7 @@ FLXPostgresResultRowType; NSString **_fields; NSStringEncoding _stringEncoding; + FLXPostgresResultRowType _defaultRowType; FLXPostgresConnection *_connection; } @@ -62,6 +63,11 @@ FLXPostgresResultRowType; */ @property (readonly) NSStringEncoding stringEncoding; +/** + * @property defaultRowType The row type that should be used when calling -row. + */ +@property (readwrite, assign) FLXPostgresResultRowType defaultRowType; + - (id)initWithResult:(void *)result connection:(FLXPostgresConnection *)connection; - (NSUInteger)numberOfFields; @@ -70,6 +76,7 @@ FLXPostgresResultRowType; - (NSArray *)fields; +- (id)row; - (NSArray *)rowAsArray; - (NSDictionary *)rowAsDictionary; - (id)rowAsType:(FLXPostgresResultRowType)type; diff --git a/Frameworks/PostgresKit/Source/FLXPostgresResult.m b/Frameworks/PostgresKit/Source/FLXPostgresResult.m index 57a26268..06950a3b 100644 --- a/Frameworks/PostgresKit/Source/FLXPostgresResult.m +++ b/Frameworks/PostgresKit/Source/FLXPostgresResult.m @@ -38,6 +38,7 @@ @synthesize numberOfRows = _numberOfRows; @synthesize numberOfFields = _numberOfFields; @synthesize stringEncoding = _stringEncoding; +@synthesize defaultRowType = _defaultRowType; #pragma mark - #pragma mark Initialisation @@ -73,6 +74,7 @@ _connection = [connection retain]; _stringEncoding = [_connection stringEncoding]; + _defaultRowType = FLXPostgresResultRowAsDictionary; _typeHandlers = (void **)calloc(sizeof(void *), _numberOfFields); @@ -114,6 +116,16 @@ #pragma mark - #pragma mark Data Retrieval +/** + * Return the current row in the type of the currently set default (defaults to dictionary). + * + * @return The row of data. + */ +- (id)row +{ + return [self rowAsType:_defaultRowType]; +} + /** * Return the current row as an array. * @@ -143,9 +155,7 @@ { if (_row >= _numberOfRows) return nil; - id data; - - data = (type == FLXPostgresResultRowAsArray) ? [NSMutableArray arrayWithCapacity:_numberOfFields] : [NSMutableDictionary dictionaryWithCapacity:_numberOfFields]; + id data = (type == FLXPostgresResultRowAsArray) ? [NSMutableArray arrayWithCapacity:_numberOfFields] : [NSMutableDictionary dictionaryWithCapacity:_numberOfFields]; for (NSUInteger i = 0; i < _numberOfFields; i++) { -- cgit v1.2.3