Objective-C in the Cloud

PGCResult Class Reference

Declared inPGCKit/PGCResult.h
Base classNSObject
Guides

Overview

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.

Working with a result object

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.

Tasks

Closing

-close

Retrieving Data

@numberOfRows
@numberOfColumns
-boolForRow:column:
-boolForRow:columnIndex: -integerForRow:column:
-integerForRow:columnIndex:
-stringForRow:column:
-stringForRow:columnIndex:
-dateForRow:column:
-dateForRow:columnIndex:
-objectValueForRow:columnIndex:
-objectValueForRow:column:

Convenience

- dictionaryForRow:
- enumerateRowsUsingBlock:

Declared Properties

numberOfColumns

The number of columns of the receiver.

@property (readonly) NSUInteger numberOfColumns

Discussion

The number of the columns the receiver contains.

numberOfRows

The number of rows of the receiver.

@property (readonly) NSUInteger numberOfRows

Discussion

The number of the rows the receiver contains.

Instance Methods

boolForRow:column:

Returns a boolean value for the given row and column of the receiver.

- (BOOL)boolForRow:(NSUInteger)row column:(NSString *)column

Parameters

row
The row index of the value
column
The column name of the value

Discussion

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:.

See also

-boolForRow:columnIndex:

boolForRow:columnIndex:

Returns a boolean value for the given row and column of the receiver.

- (BOOL)boolForRow:(NSUInteger)row columnIndex:(NSInteger)column

Parameters

row
The value's row index
columnIndex
The value's column index

Discussion

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:.

See also

-boolForRow:column:

close

Closes the result

- (void)close

Discussion

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.

dateForRow:column:

Returns a date for the given row and column of the receiver.

- (NSDate *)dateForRow:(NSUInteger)row column:(NSString *)column

Parameters

row
The row index of the value
column
The column name of the value

Discussion

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.

See also

-dateForRow:columnIndex:

dateForRow:columnIndex:

Returns date for the given row and column of the receiver.

- (NSDate *)dateForRow:(NSUInteger)row columnIndex:(NSInteger)column

Parameters

row
The value's row index
columnIndex
The value's column index

Discussion

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.

See also

-dateForRow:column:

integerForRow:column:

Returns an integer for the given row and column of the receiver.

- (NSInteger *)integerForRow:(NSUInteger)row column:(NSString *)column

Parameters

row
The row index of the value
column
The column name of the value

Discussion

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:.

See also

-integerForRow:columnIndex:

integerForRow:columnIndex:

Returns an integer for the given row and column of the receiver.

- (NSInteger)integerForRow:(NSUInteger)row columnIndex:(NSInteger)column

Parameters

row
The value's row index
columnIndex
The value's column index

Discussion

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:.

See also

-integerForRow:column:

stringForRow:column:

Returns a string for the given row and column of the receiver.

- (NSSString *)stringForRow:(NSUInteger)row column:(NSString *)column

Parameters

row
The row index of the value
column
The column name of the value

Discussion

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.

See also

-stringForRow:columnIndex:

stringForRow:columnIndex:

Returns a string for the given row and column of the receiver.

- (NSString *)stringForRow:(NSUInteger)row columnIndex:(NSInteger)column

Parameters

row
The value's row index
columnIndex
The value's column index

Discussion

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.

See also

-stringForRow:column:

objectValueForRow:columnIndex:

Returns a object value for the given row and column of the receiver.

- (id)objectValueForRow:(NSUInteger)row columnIndex:(NSUInteger)column

Parameters

row
The value's row index
columnIndex
The value's column index

Discussion

Returns an object that represents the value in the receiver at the given row and column. Row and columns are specified by integers.

See also

-objectValueForRow:column:

objectValueForRow:column:

Returns a object value for the given row and column of the receiver.

- (id)objectValueForRow:(NSUInteger)row column:(NSString *)column

Parameters

row
The value's row index
column
Name of the column of interest

Discussion

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.

See also

-objectValueForRowIndex:column:

dictionaryForRow:

Returns a dictionary which contains the data of the result set at the given row. - (NSDictionary *)dictionaryForRow:(NSUInteger)row

Parameters

row
Index of the row of interest

Discussion

enumerateRowsUsingBlock:

Executes the given block for each row in the result object.

- (void)enumerateRowsUsingBlock:(void (^)(NSDictionary *row, BOOL *stop))block

Parameters

block
A block that is invoked for each row in the result set. Rows are represented by dictionaries. The stop flag allows you to stop the enumeration.

Discussion