diff options
author | stuconnolly <stuart02@gmail.com> | 2012-09-16 04:27:12 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-09-16 04:27:12 +0000 |
commit | a0b76fba5ade5b1c018cb7ebcfae193cec114f5f (patch) | |
tree | 3a64048771b0fed2efac5de13176c6a4c28031fc /Frameworks/PostgresKit | |
parent | 202413b252af301e314a097b3deda6ac1a592a2a (diff) | |
download | sequelpro-a0b76fba5ade5b1c018cb7ebcfae193cec114f5f.tar.gz sequelpro-a0b76fba5ade5b1c018cb7ebcfae193cec114f5f.tar.bz2 sequelpro-a0b76fba5ade5b1c018cb7ebcfae193cec114f5f.zip |
Add the ability to set the default row return type.
Diffstat (limited to 'Frameworks/PostgresKit')
-rw-r--r-- | Frameworks/PostgresKit/Source/FLXPostgresResult.h | 9 | ||||
-rw-r--r-- | Frameworks/PostgresKit/Source/FLXPostgresResult.m | 16 |
2 files changed, 21 insertions, 4 deletions
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); @@ -115,6 +117,16 @@ #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. * * @return The array of data. @@ -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++) { |