2011-05-09 4 views
1

정말 이상한 점이 있습니다. 나는 완벽하게 작동하는 방법을 가지고 있지만, 데이터가 더 많은 데이타베이스를 구동하도록 변환하려고합니다. 현재 존재하는 하드 코딩과 비교됩니다. 데이터를 가져 오기 위해 데이터베이스 메서드에 호출을 추가하면 데이터베이스 항목이 완료된 후에도 EXC_BAD_ACCESS가 오게됩니다. 나는 데이터베이스 물건에 이르기까지 그것을 좁혔습니다. 왜냐하면 제가 전화를 전혀하지 않으면 크래시가 발생하지 않기 때문입니다.iOS + sqlite 문제 (EXC_BAD_ACCESS)

NSString *thisRoomNumber = [self readLocationsFromDatabaseBetweenPoints:fX YPoint:fY]; 

및 방법 자체는 다음과 같습니다 :

그래서, 방법에 대한 호출이 (내가 주석 경우,이 충돌하지 않는 곳은) 다음과 같습니다

#pragma mark - 
#pragma mark SQL Operations 
- (NSString *)readLocationsFromDatabaseBetweenPoints:(float)tapPointX YPoint:(float)tapPointY{ 

    // Setup some globals 
    databaseName = @"db.sqlite"; 

    // Get the path to the documents directory and append the databaseName 
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDir = [documentPaths objectAtIndex:0]; 
    databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; 

    // Setup the database object 
    sqlite3 *database; 

    NSString *sqlStringBuilder = [NSString stringWithFormat:@"select * from floors where propertyid = ? and floorid = ? and %f between topleftxcoord and bottomrightxcoord and %f between topleftycoord and bottomrightycoord", tapPointX, tapPointY]; 

    NSString *roomNumber = @"0"; 

    // Open the database from the users filessytem 
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { 
     // Setup the SQL Statement and compile it for faster access 
     const char *sqlStatement = [sqlStringBuilder UTF8String]; 

     NSLog(@"%@", [NSString stringWithUTF8String:sqlStatement]); 

     sqlite3_stmt *compiledStatement; 
     if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { 
      sqlite3_bind_int(compiledStatement, 1, iPropertyId); 
      sqlite3_bind_int(compiledStatement, 2, iFloorId);   

      // Loop through the results and add them to the feeds array 
      while(sqlite3_step(compiledStatement) == SQLITE_ROW) { 
       // Read the data from the result row 
       NSInteger aLocId = sqlite3_column_int(compiledStatement, 0); 
       NSInteger aTLX = sqlite3_column_int(compiledStatement, 1); 
       NSInteger aTLY = sqlite3_column_int(compiledStatement, 2); 
       NSInteger aBRX = sqlite3_column_int(compiledStatement, 3); 
       NSInteger aBRY = sqlite3_column_int(compiledStatement, 4); 
       NSString *aRoomIdent = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)]; 

       roomNumber = aRoomIdent; 

      } 
     }else{ 
      NSLog(@"%d", sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL)); 
     } 
     // Release the compiled statement from memory 
     sqlite3_finalize(compiledStatement); 

    } 
    sqlite3_close(database); 


    [documentsDir release]; 
    [documentPaths release]; 
    //[roomNumber release]; 
    [sqlStringBuilder release]; 

    return roomNumber; 
} 

호출 자체가 정상적으로 작동합니다. 예상대로 결과를 얻습니다. "thisRoomNumber"는 내가 기대하는 것으로 돌아옵니다. 호출 메서드가 다음 부분으로 나가면 대표자에게 돌아가고, 이때 충돌이 발생합니다. 사용할 코드가 많지 않고 계속 진행되는 것을보기가 어렵다는 것을 알고 있지만 코드가 많아서이 게시물을 엄청나게 만들 수 있습니다.

이렇게하면 문제를 해결할 수있는 출발점이됩니다. 또한 크래시 로그 덤프는이 작업에 전혀 도움이되지 않습니다.

도움을 주셔서 감사합니다. 추가 정보가 필요하면 알려주세요. 필요에 따라 추가 할 수 있도록 최선을 다할 것입니다.

+0

실수로 참조 횟수를 줄이면 안됩니다. '빌드 및 분석'에서 경고를 주시겠습니까? – James

+0

나는 실제 경고를받지 못한다. (내가 아는 몇 가지 것들을 제외하고는 아무것도 사용하지 않았다. 사용하지 않은 값 등이 있지만 영원히 그곳에 있었다. 나는 그 부분을 끝내기 위해 돌아 다녔다.) – SlackerCoder

답변

1

끝에 릴리스 요청이 문제입니다. 당신이 소유하지 않은 물건을 공개하고 있습니다. 그들을 제거하고 당신은 잘되어야한다.

+0

내가 왜 그 일을했는지 ​​모르겠다. – SlackerCoder