잘하면이 말이 맞는 것입니다. 내 문서 폴더에 sqlite 데이터베이스가 있습니다. 또한 해당 파일이 디렉토리에 있는지 확인하는 기능이 있습니다. 그렇지 않으면 기본 번들에서 해당 파일이 이동됩니다. 그래서 데이터베이스가 올바른 위치에 있다는 것을 알고 있습니다. 그러나, 내 애플 리케이션을 실행할 때 오류가 발생합니다 : 해당 테이블 : databaseName. 문제는 sqlite 데이터베이스의 읽기 쓰기 액세스와 관련이 있습니까? 그렇다면이 문제를 확인하고 문제를 해결하는 방법은 무엇입니까?객관적인 c에서 sqlite의 쓰기 권한 읽기
#define kFilename @"foods.sqlite"
- (NSString *)dataFilePath {
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* sqliteFile = [documentsPath stringByAppendingPathComponent:kFilename];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:sqliteFile];
if(fileExists)
return sqliteFile;
else {
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:kFilename];
NSString *folderPath = [documentsPath stringByAppendingPathComponent:kFilename];
NSError *error;
[[NSFileManager defaultManager] copyItemAtPath:sourcePath
toPath:folderPath
error:&error];
NSLog(@"Error description-%@ \n", [error localizedDescription]);
NSLog(@"Error reason-%@", [error localizedFailureReason]);
}
return [documentsPath stringByAppendingPathComponent:kFilename];
}
-(void) viewWillAppear:(BOOL)animated{
sqlite3 *database;
if (sqlite3_open([[self dataFilePath] UTF8String], &database)
!= SQLITE_OK) {
sqlite3_close(database);
NSAssert(0, @"Failed to open database");
}
sqlite3_stmt *statement;
//why is this if statement failing?
if (sqlite3_prepare_v2(database, [sqlStatement UTF8String],
-1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
//int row = sqlite3_column_int(statement, 0);
char *rowData = (char *)sqlite3_column_text(statement, 1);
foodName = [[NSString alloc] initWithUTF8String:rowData];
[foodArray addObject:foodName];
}
sqlite3_finalize(statement);
}
else {
NSLog(@"%i", sqlite3_prepare_v2(database, [sqlStatement UTF8String],
-1, &statement, nil));
NSLog(@"Statement: %s", sqlite3_errmsg(database));
}
sqlite3_close(database);
}
코드를 보여 주시겠습니까? – pasawaya
방금 –