Well i am new to iphone coding and using sqlite in one of my application the problem is my sqlite database does not updates the modified data, i am following a sqlite based tutorial:
this is what i am doing:-
- (void) saveAllData {
if(isDirty) {
if(updateStmt == nil) {
const char *sql = "update Work Set Engagement = ?, Status = ?, Where WorkID = ?";
if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_text(updateStmt, 1, [Engagement UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 2, [Status UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_double(updateStmt, 2, [Status doubleValue]);
sqlite3_bind_int(updateStmt, 3, WorkID);
//int Success = sqlit3_step(updateStmt);
if(SQLITE_DONE != sqlite3_step(updateStmt))
NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
sqlite3_finalize(updateStmt);
isDirty = NO;
}
i am using :
- (IBAction) save_Clicked:(id)sender {
//Update the value.
//Invokes the set<key> method defined in the Work Class.
[objectToEdit setValue:txtField.text forKey:self.keyOfTheFieldToEdit];
[self.navigationController popViewControllerAnimated:YES];
}
for save button click and :
- (void) setEngagement:(NSString *)newValue {
self.isDirty = YES;
[Engagement release];
Engagement = [newValue copy];
}
- (void) setStatus:(NSString *)newNumber {
self.isDirty = YES;
[Status release];
Status = [newNumber copy];
}
for setting values, i banged my head thousand times and can not find what i am doing wrong can some body plz help me with this.....
this is the code for my getDBPath implementation
(NSString *) getDBPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; return [documentsDir stringByAppendingPathComponent:@"CheckList.sqlite"]; }
this code for my Data Base : - (void) copyDatabaseIfNeeded {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];
if(!success) {
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"CheckList.sqlite"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}