그래서이 프로젝트를 잠깐 동안 진행해 왔습니다. DB에서 데이터를 읽고 UITableViews로 포맷하는 데 아무런 문제가 없습니다. 하지만 지금은 DB에 글을 쓰고 싶습니다. 문제는 sqlite에서 "Database is Locked"오류가 계속 발생하는 것입니다. 원래 버전으로 어지러운 후에 나는 데이터베이스가 번들에 있다는 것을 깨닫게되었고, 따라서 쓸모가 없었습니다. 그래서 필자는 DB를 쓰기가 가능한 Apps Documents 폴더로 재배치했습니다. 하지만 지금은 여전히 "데이터베이스 잠김"SQL 오류가 발생합니다. 필요한 경우에만 DB를 열고 닫습니다. 그리고 제가 말할 수있는 한, 나는 어디에서나 열어 두지 않습니다. 아래 코드는 내가 업데이트를하고 싶습니다. 이견있는 사람?iPhone sqlite3 잠김, 읽을 수만 있음, 쓸 수 없음
- (BOOL) loanBookTo:(NSString *)newborrower{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"books.sqlite"];
if([[NSFileManager defaultManager] fileExistsAtPath:path]){
NSLog(@"File Exists at: %@", path);
}
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
NSString *mySQL = @"UPDATE BOOKS SET LOANED = 1, BORROWER = \"<BORROWER>\" where ISBN = \"<ISBN>\"";
mySQL = [mySQL stringByReplacingOccurrencesOfString:@"<ISBN>" withString:self.isbn];
mySQL = [mySQL stringByReplacingOccurrencesOfString:@"<BORROWER>" withString:newborrower];
const char *sql = [mySQL UTF8String];
char* errmsg;
sqlite3_exec(database, sql, NULL, NULL, &errmsg);
// Q. Database is locked. Why?
// A. Because it is in the Bundle and is ReadOnly.
// Need to write a copy to the Doc folder.
// Database is Locked error gets spit out here.
printf(errmsg);
sqlite3_close(database);
}
return NO;
}
응용 프로그램 번들 또는 문서 디렉토리의 DB는 어디에 있습니까? – zaph