Declared in | PGCKit/PGCResult.h |
Base class | NSObject |
Guides |
A PGCResult
represents the result of a query. You never create an instance object of PGCResult
with +alloc
et al., but receive it as the expression result of sending execute:withArguments:error:
to a PGCConnection
instance object.
PGCResult
uses libpq. The maximum limits of libpq are in effect.
Once you have a result object you may want to retrieve the data it represents. This can be done is many different ways. The easiest way to get data from a result object is to use a simple for-loop:
PGCConnection *connection = [self defaultDatabaseConnection];
PGCResult *result = [self resultWithConnection:connection];
for(NSDictionary *row in result) {
NSDate *birthday = row[@"birthday"];
NSLog(@"birthday: %@", birthday);
}
You can use a simple for-loop to iterate over the result. Each row in the result is represented by an NSDictionary
. You can use subscripting/-objectForKey:
to retrieve the values for columns present in the result.
If you don't want to iterate over a result set but retrieve the results directly you can do so with the methods listed in the section called Retrieving Data. Those methods all work the same: You need to know the number of the row you are interested in and either the number of the column or the name of the column.
@numberOfRows
@numberOfColumns
-boolForRow:column:
-boolForRow:columnIndex:
-integerForRow:column:
-integerForRow:columnIndex:
-stringForRow:column:
-stringForRow:columnIndex:
-dateForRow:column:
-dateForRow:columnIndex:
-objectValueForRow:columnIndex:
-objectValueForRow:column:
- dictionaryForRow:
- enumerateRowsUsingBlock:
The number of columns of the receiver.
@property (readonly) NSUInteger numberOfColumns
The number of the columns the receiver contains.
The number of rows of the receiver.
@property (readonly) NSUInteger numberOfRows
The number of the rows the receiver contains.
Returns a boolean value for the given row and column of the receiver.
- (BOOL)boolForRow:(NSUInteger)row column:(NSString *)column
Returns a BOOL
that represents the value in the receiver at the given row and column. The row is specified by an integer, the column name by an instance object of NSString
.
If the value is the NULL
-value then NO
is returned. If you want to check for NULL
use -isNullValueForRow:column:
.
Returns a boolean value for the given row and column of the receiver.
- (BOOL)boolForRow:(NSUInteger)row columnIndex:(NSInteger)column
Returns a BOOL
that represents the value in the receiver at the given row and column. Row and columns are specified by integers.
If the value is the NULL
-value then NO
is returned. If you want to check for NULL
use -isNullValueForRow:column:
.
Closes the result
- (void)close
Closes the result object and releases all underlying resources. You should explicitly close result objects when you are done with them. If an instance object of PGCResult
is deallocated before it is closed, this will be logged. It is undefined behavior, whether the underlying resources are freed or not.
Sending close
to the receiver after it already received close
leads to undefined behavior.
Returns a date for the given row and column of the receiver.
- (NSDate *)dateForRow:(NSUInteger)row column:(NSString *)column
Returns an instance object of NSDate
that represents the value in the receiver at the given row and column. The row is specified by an integer, the column name by an instance object of NSString
.
Returns date for the given row and column of the receiver.
- (NSDate *)dateForRow:(NSUInteger)row columnIndex:(NSInteger)column
Returns an instance object of NSDate
that represents the value in the receiver at the given row and column. Row and columns are specified by integers.
Returns an integer for the given row and column of the receiver.
- (NSInteger *)integerForRow:(NSUInteger)row column:(NSString *)column
Returns a value of type NSInteger
that represents the value in the receiver at the given row and column. The row is specified by an integer, the column name by an instance object of NSString
.
If the value is the NULL
-value then NSIntegerMin
is returned. If you want to check for NULL
use -isNullValueForRow:column:
.
Returns an integer for the given row and column of the receiver.
- (NSInteger)integerForRow:(NSUInteger)row columnIndex:(NSInteger)column
Returns a value of type NSInteger
that represents the value in the receiver at the given row and column. Row and columns are specified by integers.
If the value is the NULL
-value then NSIntegerMin
is returned. If you want to check for NULL
use -isNullValueForRow:column:
.
Returns a string for the given row and column of the receiver.
- (NSSString *)stringForRow:(NSUInteger)row column:(NSString *)column
Returns an instance object of NSString
that represents the value in the receiver at the given row and column. The row is specified by an integer, the column name by an instance object of NSString
.
Returns a string for the given row and column of the receiver.
- (NSString *)stringForRow:(NSUInteger)row columnIndex:(NSInteger)column
Returns an instance object of NSString
that represents the value in the receiver at the given row and column. Row and columns are specified by integers.
Returns a object value for the given row and column of the receiver.
- (id)objectValueForRow:(NSUInteger)row columnIndex:(NSUInteger)column
Returns an object that represents the value in the receiver at the given row and column. Row and columns are specified by integers.
Returns a object value for the given row and column of the receiver.
- (id)objectValueForRow:(NSUInteger)row column:(NSString *)column
Returns an object that represents the value in the receiver at the given row and column. The row is specified by an integer, the column name by an instance object of NSString
.
-objectValueForRowIndex:column:
Returns a dictionary which contains the data of the result set at the given row.
- (NSDictionary *)dictionaryForRow:(NSUInteger)row
Executes the given block for each row in the result object.
- (void)enumerateRowsUsingBlock:(void (^)(NSDictionary *row, BOOL *stop))block