2013-10-10 2 views
0

나는이 내 코드에서 다음 문 :sqlite3_open - 열 수 없습니다 데이터베이스

NSString *docsDir; 
NSArray *dirPaths; 

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES); 
docsDir = [dirPaths objectAtIndex:0]; 

databasePath = [[NSString alloc] initWithString:[docsDir stringByAppendingPathComponent:@"Notebook.sqlite"]]; 
NSFileManager *fileMgr = [NSFileManager defaultManager]; 
const char *dbpath = [databasePath UTF8String]; 
NSLog(@"open sqlite at %s",dbpath); 
if (sqlite3_open(dbpath, &noteDB)==SQLITE_OK) 

NSLog의 출력이

/사용자 /입니다 GinLin/라이브러리/응용 프로그램 지원/아이폰 시뮬레이터/7.0/응용 프로그램/CE1BAB1C-3DEC-4A1D-A083-537B0B51C99D/도서관/설명서/

Notebook.sqlite하지만 내 데이터베이스를 여는 될 것 같지 않습니다. 그리고 "/ CE1BAB1C-3DEC-4A1D-A083-537B0B51C99D/Library /"에서 "Documentation"폴더를 찾을 수 없습니다.

아무도 도와 줄 수 있습니까?

답변

0

내가 DB 경로가 드 파일을 포함하는 경우

NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *docsDir = [dirPaths objectAtIndex:0]; 
+1

예를 복사! 그것은 작동합니다! 대단히 감사합니다. – Zheng

0

먼저 당신이 다른, 확인해야합니다 : 당신이 NSDocumentDirectory하지 NSDocumentationDirectory를 사용하는 의미 예컨대 믿는다 DB

NSFileManager *fileMgr = [NSFileManager defaultManager]; 
NSString* resourcePath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"]; 

    //Destination path 
NSString *dbPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"database.db"]; 
    //Find file 
BOOL success = [fileMgr fileExistsAtPath:dbPath]; 
if(success==YES){ 
    NSLog(@"File found"); 
}else{ 
    NSError* error; 
    if(![fileMgr copyItemAtPath:resourcePath toPath:dbPath error:&error]){ 
     NSLog(@"Can't copy"); 
    }else{ 
     NSLog(@"That's all :D"); 
    } 
} 
관련 문제