我正在使用 FMDB 执行下面的选择查询,它在 iOS 8.2 之前工作。此查询在 iOS 8.1 及更早版本中返回了完美的结果集。但是当我在 Xcode 6.2 和 iOS 8.2 中安装应用程序并调试相同的代码时,编译器卡在sqlite3_step上。任何人都知道为什么会这样。下面是查询和代码。
resultset = [manager420 selectFromTable:[NSString stringWithFormat:@"select Call_HDR.*, Problem.Machine, Problem.ServiceStatusFlag, AssignTech.RepName AS AssignTechName, DefaultTech.RepName AS DefaultTechName, Problem.ProblemDescription AS ProblemDescription, Problem.SLAHours AS SLAHours, ARComment.CustARComments As CustARComments, SLAResponseCode.SLAResponse As SLAResponse, ( 'E(' || IFNULL(Call_Status.ESum,0) || ') P(' || IFNULL(Call_Status.PSum,0) || ') O/P(' || IFNULL(Call_OPCount.RecordCount,0) || ')') AS EPO, (IFNULL(Call_Status.ECSum,0) || ' ' || IFNULL(Call_Status.PCSum,0)) AS EPC from CALL_HDR LEFT JOIN Branch_Reps as AssignTech ON CALL_HDR.RepID = AssignTech.RepID LEFT JOIN Branch_Reps as DefaultTech ON CALL_HDR.AssignedServiceRep = DefaultTech.RepID LEFT JOIN CALL_MACHINE as Problem ON CALL_HDR.CallNumber||'*001' = Problem.CallNumberWSeqnbr LEFT JOIN (Select Call_Machine.CallNumber, IFNULL(COUNT(CASE WHEN Call_Machine.EmergencyServicePerformed IN ('Y', 'C') THEN 1 END), 0) As ESum, IFNULL(COUNT(CASE WHEN Call_Machine.EmergencyServicePerformed = 'C' THEN 1 END), 0) As ECSum, IFNULL(COUNT(CASE WHEN Call_Machine.EmergencyServicePerformed NOT IN ('Y', 'C') THEN 1 END), 0) As PSum, IFNULL(COUNT(CASE WHEN Call_Machine.PMIAInspectionPerformed = 'Y' THEN 1 END), 0) As PCSum From Call_Machine Group By Call_Machine.CallNumber) As Call_Status ON CALL_HDR.CallNumber = Call_Status.CallNumber LEFT JOIN (SELECT COUNT(*) RecordCount,CC.CALLNumber FROM Machines M INNER JOIN Call_Hdr CC ON M.Location_ID = CC.LocationID WHERE M.Next_insp_Due_Date <> '' AND NOT EXISTS (Select Call_Machine.SNID from Call_Machine where Call_Machine.CallNumber = CC.CallNumber AND Call_Machine.SNID = M.Snrrn) GROUP BY CC.CallNumber) As Call_OPCount ON CALL_HDR.CallNumber = Call_OPCount.CallNumber LEFT JOIN Customers as ARComment ON CALL_HDR.LocationID = ARComment.LocationID LEFT JOIN NA_Data as SLAResponseCode ON CALL_HDR.CustomerTypeCode = SLAResponseCode.NationalAccountCode where CALL_HDR.CallStatus <> '%@' AND CALL_HDR.CallStatus <> '%@' %@",STATUS_CLOSED,STATUS_CANCELLED,temp_Query]];
while ([resultset next]) {
NSLog(@"result returned !!");
}
编译卡在结果集类的下一个方法中,而不是从 sqlite3_step 方法继续。
- (BOOL) next {
int rc;
BOOL retry;
int numberOfRetries = 0;
do {
retry = NO;
rc = sqlite3_step(statement.statement);
if (SQLITE_BUSY == rc) {
// this will happen if the db is locked, like if we are doing an update or insert.
// in that case, retry the step... and maybe wait just 10 milliseconds.
retry = YES;
usleep(20);
if ([parentDB busyRetryTimeout] && (numberOfRetries++ > [parentDB busyRetryTimeout])) {
NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [parentDB databasePath]);
NSLog(@"Database busy");
break;
}
}
else if (SQLITE_DONE == rc || SQLITE_ROW == rc) {
// all is well, let's return.
}
else if (SQLITE_ERROR == rc) {
NSLog(@"Error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([parentDB sqliteHandle]));
break;
}
else if (SQLITE_MISUSE == rc) {
// uh oh.
NSLog(@"Error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([parentDB sqliteHandle]));
break;
}
else {
// wtf?
NSLog(@"Unknown error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([parentDB sqliteHandle]));
break;
}
} while (retry);
if (rc != SQLITE_ROW) {
[self close];
}
return (rc == SQLITE_ROW);
}
提前致谢。