libpq (C로 작성)을 기반으로 Objective-C에 PostgreSQL 라이브러리를 작성하고 있습니다. PQexec
을 성공적으로 사용하는 동기식 쿼리 메서드를 작성한 반면, 내 비동기 메서드는 쿼리 결과를받지 못합니다. PQgetResult
은 항상 NULL
을 반환합니다.PQgetResult는 항상 NULL을 반환합니다.
다양한 조합의 연결 및 쿼리 검사를 시도했지만 문제를 해결하지 못했습니다. 쿼리 자체는 한 행이있는 테이블의 SELECT
입니다. 동기 메서드에 대해이 비동기 메서드를 스왑하고 원하는 동작을 수행 할 수 있습니다. 또한 내가 유지하고있는 conn
포인터가 동일한 객체를 전체적으로 참조하고 있는지 확인했습니다.
나는 이 아니며, 단일 행 모드를 사용합니다.입니다. 문제를 디버그하는 데 도움하려면
+ (instancetype) resultSetWithQuery: (NSString*) query usingConnection: (PGConnection*) conn whenComplete: (Callback) callback {
PGResultSet* resultSet = [[PGResultSet alloc] init];
NSString* encoding = [conn encoding];
int success = PQsendQuery([conn conn], [query UTF8String]);
[resultSet setEncoding:encoding];
[resultSet setQuery:query];
[resultSet setConn:conn];
if(success){
NSTimeInterval timeInterval = 0.5;
NSTimer* checkStatus = [NSTimer scheduledTimerWithTimeInterval:timeInterval
target:resultSet
selector:@selector(checkIfComplete)
userInfo:nil
repeats:YES];
[resultSet setTimer:checkStatus];
[resultSet setCallback:callback];
}
return resultSet;
}
- (void)checkIfComplete{
if(!PQconsumeInput([[self conn] conn])){
[[self timer] invalidate];
}
if(PQisBusy([[self conn] conn])){
return;
}
// result is always NULL
PGresult* result = PQgetResult([[self conn] conn]);
// ...
}