У меня проблема с обновлением данных. Я использую этот код для обновления.
Все идет хорошо, но мои данные не обновляются. в чем проблема в этом?
Я бы хотел обновить значение столбца EndDate: его тип данных - DATETIME.
Все выполняется очень хорошо, но моя таблица базы данных UserDourney EndDate не получает обновления В чем проблема и как я могу ее решить?
-(void)journeyEnd
{
NSString *filePath = [self getWritableDBPath];
sqlite3 *database;
NSDate* date = [NSDate date];
//Create the dateformatter object
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
//Set the required date format
[formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
//Get the End date
NSString* str = [formatter stringFromDate:date];
NSLog(@"this from new map '%@'",journeyid);
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
**this line where i am trying to insert statement after that i remember that i have fire the UPDATE statement**
//const char *sqlStatement = "insert into UserJourney(EndDate) VALUES (?) where JourneyID = ''";
//And here I fire the Update statement
NSString *sqlStatement = [NSString stringWithFormat:@"UPDATE UserJourney SET EndDate='%@' WHERE JourneyID='%@'",str,journeyid];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String] , -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_text( compiledStatement, 1, [str UTF8String], -1, SQLITE_TRANSIENT);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE ) {
NSLog( @"Save Error: %s", sqlite3_errmsg(database) );
}
else {
sqlite3_reset(compiledStatement);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Record added" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert = nil;
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}