저는 iOS 5.1을 대상으로하고 응용 프로그램 파일에서 내 문서 폴더로 데이터베이스를 복사하려고합니다. 나는 과거에이 동일한 코드로 이것을 해왔으므로 이번에는 왜 작동하지 않는지 조금 혼란 스럽다.데이터베이스를 복사 할 수 없습니다
이것은 존재하는지 확인하고 그렇지 않은 경우 복사하는 데 사용하는 방법입니다. 그것은 here입니다.
내가 이렇게 이렇게하려면 DB를 조회하려고
-(void) checkAndCreateDatabase{
// Check if the SQL database has already been saved to the users phone, if not then copy it over
BOOL success;
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:self.databasePath];
// If the database already exists then return without doing anything
if(success) return;
NSLog(@"Installing db: %@", self.databasePath);
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:self.databasePath error:nil];
//[databasePathFromApp release];
//[fileManager release];
} :
sqlite3 *database1;
// Open the database from the users filessytem
if(sqlite3_open([self.databasePath UTF8String], &database1) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
NSString *sqlStatement = [NSString stringWithFormat: @"update login set is_logged=0"];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database1, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {
if(SQLITE_DONE != sqlite3_step(compiledStatement)){
NSAssert1(0, @"Error while updating logged. '%s'", sqlite3_errmsg(database1));
NSLog(@"Error setting logged_in to 0: %s", sqlite3_errmsg(database1));
}
else{
NSLog(@"Made Logged_in=0");
}
}
else{
NSLog(@"Prop problem1: %s", sqlite3_errmsg(database1));
NSLog(@"Couldn't prep 1");
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
else{
NSLog(@"Couldn't even open db1");
}
sqlite3_close(database1);
sqlite3_open()
기능 no such table: login
의 sqlite3_errmsg
로이 경우에는 false를 돌려줍니다.
이 데이터베이스 개체를 사용하는 개체를 만드는 매 초마다 호출되는 함수가 있습니다. 데이터베이스가 그 초에 복사되지 않았고 다음 호출이 이전 사본을 인터럽트 할 수 있습니까? 그럴 가능성이 없다.
어떤 아이디어가 문제 일 수 있습니까?
솔루션 는이 질문 상담 : here 및 소수점 숫자 2에 따라 내 데이터베이스가 "복사 번들 리소스"목록에없는 것을 보인다. 나는 그것을 추가했고 모든 것이 이제는 괜찮아 보인다.
나를 올바른 방향으로 생각하게 해줘서 고마워.
Organizer를 사용하여 전화에서 파일을 다운로드하고 복사 된 내용을 확인하십시오. (Apple의 새로운 5.1 표준을 사용하려면 DB 파일을 "백업하지 마십시오"라고 표시해야합니다.) –
문서 폴더에는 내용이 비어 있지만 내용이 비어 있습니다. 나는 이것이 SQL 파일의 인코딩 문제와 관련 있다고 가정 할 것입니다. – emachine
스크래치, 방금 애플 리케이션을 삭제하고 다시 설치하고 데이터베이스가 문서 폴더에 없습니다. [empty] 데이터베이스 파일은 쿼리를 시도한 후에 만 나타나는 것으로 보입니다. – emachine