我有一個非常奇怪的問題。我有一種方法可以很好地工作,但我試圖將其轉換爲使數據更多地驅動數據庫與當前存在的硬編碼。當我添加一個對數據庫方法的調用來提取數據時,我得到一個EXC_BAD_ACCESS long數據庫內容完成後。我把它縮小到數據庫的東西,因爲如果我根本不打電話,崩潰不會發生。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」返回了我期望的結果。一旦調用方法踢出到下一個部分,它就會返回到委託,在此時它崩潰。我知道很難看到發生了什麼,沒有很多代碼可以使用,但是大量的代碼會使這個帖子成爲MASSIVE。
希望這會給我們一個解決這個問題的出發點。另外,崩潰日誌轉儲對此沒有任何用處。
感謝您提供任何幫助!如果您需要更多信息,請告訴我,我會盡我所能根據需要添加此信息。
您可能意外地減少了您不應該做的事情的引用計數:「構建和分析」會提供任何警告嗎? – James 2011-05-09 16:53:26
我根本沒有得到任何真實的警告(除了我知道的一些東西,不會破壞任何東西 - 一些未使用的值等,但那些東西永遠在那裏,我只是沒有回過頭來完成那部分) – SlackerCoder 2011-05-09 17:19:01