행의 셀 하나만 업데이트하려고하지만 작업을 수행 할 수 없습니다. 업데이트에 대한 방법 : sqlite에서 업데이트 행이 업데이트되지 않습니다.
- (void) UpdateQuestionShownParameter:(int)QuestionId :(BOOL)QuestionShown{
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"Milionar.sqlite"];
const char *sql = "UPDATE Questions set Show = ? WHERE id = ?";
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK)
{
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare_v2(db, sql, -1, &sqlStatement, NULL) == SQLITE_OK)
{
NSInteger shownInteger = (QuestionShown ? 1 : 0);
sqlite3_bind_int(sqlStatement, 1, shownInteger);
sqlite3_bind_int(sqlStatement, 2, QuestionId);
if (sqlite3_step(sqlStatement) != SQLITE_DONE)
{
NSLog(@"Error while updating. '%s'", sqlite3_errmsg(db));
}
sqlite3_finalize(sqlStatement);
}
else
{
NSLog(@"Problem with prepare statement");
}
}
else
{
NSLog(@"An error has occured while opening database.");
}
sqlite3_close(db);
}
@catch (NSException *exception) {
NSLog(@"An exception occured: %@", [exception reason]);
}
}
가있는 viewDidLoad에서 시도 :
- (void)viewDidLoad
{
ListOfQuestions *listQuestions =[[ListOfQuestions alloc] init];
self.Questions = [listQuestions getQuestions];
Question *generatedQuestion = (Question *) [self.Questions objectAtIndex:0];
[listQuestions UpdateQuestionShownParameter:generatedQuestion.id :TRUE];
[self.Description setText:(generatedQuestion.Description)];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
매번 내가 표시됨 열에 0을 얻을 응용 프로그램을 실행하려고 할 때. 그러나 나는 어떤 오류도 가지지 않는다. 그래서 내가 잘못했거나 매번 에뮬레이터에서 응용 프로그램을 실행하려고 할 때마다 프로젝트 데이터베이스에서 데이터베이스를 다시 만들었습니까? 감사합니다.
을 나는과 기사 링크와 함께 큰 팁을 찾고 정확히 무엇인지. 고마워요 ++ –