좋아, 그래서 내 iPhone 시뮬레이터 문서에 데이터베이스가 있습니다. 이제 애플리케이션 샌드 박스에 있는지 확인합니다. 내가 가진 코드에서 뭔가 이상한 점이 있습니다.Sqlite DB 해당 테이블이 없습니다
-(NSString *)getsynDbPath
{
NSString* dataBAse = [[NSBundle mainBundle] pathForResource:@"ddd"ofType:@"sqlite"];
return dataBAse;
}
그럼 내가 경로를 테스트 : 그래서 내가 먼저 DB 경로를 얻을
NSString *testData;
testData = [self getsynDbPath];
NSFileManager * fileManager = [NSFileManager defaultManager];
BOOL success = [fileManager fileExistsAtPath:testData];
if (success) {
NSLog(@"Oh no! There was a big problem!");
} else {
//Successfully opened
if(sqlite3_open([testData UTF8String], &db)==SQLITE_OK){
NSLog(@"Raise the roof!");
//Calling method to loop through columns
[self listOfCols];
}
}
그때 사용자 정의 방법으로 이동
곳 데이터베이스 내부의 열을 통해 내가 루프 :
-(NSArray *)listOfCols{
NSMutableArray *retval = [[[NSMutableArray alloc]init]autorelease];
NSString *query = @"SELECT KEY_ID FROM CON_DETAIL";
sqlite3_stmt *statement;
//Does not execute
if (sqlite3_prepare_v2(db, [query UTF8String], -1, &statement, nil)==SQLITE_OK) {
while (sqlite3_step(statement)==SQLITE_ROW) {
int key_id = sqlite3_column_int(statement, 0);
NSLog(@"Key ID: %d", key_id);
char *nameChars = (char *) sqlite3_column_text(statement, 1);
NSLog(@"chars %s", nameChars);
char *cityChars = (char *) sqlite3_column_text(statement, 2);
NSLog(@"chars %s", cityChars);
}
}
NSLog(@"%s Why '%s' (%1d)", __FUNCTION__, sqlite3_errmsg(db), sqlite3_errcode(db));
return retval;
}
여기 내 질문이 있습니다. 데이터베이스를 성공적으로 연 후에 왜 로그 오류가 발생합니까? no such table: CON_DETAIL
? 어떤 도움을 주셔서 감사합니다.
데이터베이스에 "CON_DETAIL"이라는 이야기가 있습니까? – Impossible
FMDB와 같은 래퍼를 사용하지 않는 이유는 무엇입니까? 시간 절약 ... :) – bikram990
@Impossible OP는 문서 번들이 아닌 리소스 번들에서 파일을 찾고 있습니다. – rmaddy