Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
CouchQuery error property: fixed memory leak and other issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kaalita committed Jul 2, 2012
1 parent 711b1c9 commit 0a233ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Couch/CouchQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ typedef enum {

@property BOOL sequences;

/** If non-nil, the error of the last execution of the query
If nil, the last exexution of the query was successful */
@property (readonly) NSError* error;
/** If non-nil, the error of the last execution of the query.
If nil, the last exexution of the query was successful */
@property (readonly,retain) NSError* error;

/** Starts an asynchronous query of the CouchDB view.
When complete, the operation's resultObject will be the CouchQueryEnumerator. */
Expand Down
20 changes: 11 additions & 9 deletions Couch/CouchQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ - (id) initWithDatabase: (CouchDatabase*)db result: (id)result;
@end


@interface CouchQuery ()
@property (readwrite,retain) NSError *error;
@end


@implementation CouchQuery

Expand Down Expand Up @@ -143,12 +147,11 @@ - (CouchQueryEnumerator*) rowsIfChanged {


- (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)error {
error = [super operation: op willCompleteWithError: error];
if (error) {
Warn(@"%@ failed with %@", self, error);
_error = [error retain];
}
if (!error && op.httpStatus == 200) {
self.error = [super operation: op willCompleteWithError: error];
if (_error)
Warn(@"%@ failed with %@", self, _error);

if (!_error && op.httpStatus == 200) {
NSDictionary* result = $castIf(NSDictionary, op.responseBody.fromJSON);
NSArray* rows = $castIf(NSArray, [result objectForKey: @"rows"]);
if (rows) {
Expand All @@ -157,13 +160,12 @@ - (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)erro
result: result] autorelease];
} else {
Warn(@"Couldn't parse rows from CouchDB view response");
error = [RESTOperation errorWithHTTPStatus: 502
self.error = [RESTOperation errorWithHTTPStatus: 502
message: @"Couldn't parse rows from CouchDB view response"
URL: self.URL];
_error = [error retain];
}
}
return error;
return _error;
}


Expand Down

0 comments on commit 0a233ae

Please sign in to comment.