我正在使用數據庫。當我第一次更新數據庫時,數據庫正在更新。但是,當我嘗試更新下一次不更新時,但它顯示數據庫正在更新。我知道在哪裏問題是。謝謝!數據庫沒有更新
-(void) updateData {
sqlite3_stmt *statement;
details = [updateArray objectAtIndex:0];
NSString *destinationPath = [self getDestinationPath];
const char *dbpath = [destinationPath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
NSString *updateSQL = [NSString stringWithFormat: @"UPDATE BirthdayRemainderList SET FirstName=\"%@\", LastName=\"%@\",Dob=\"%@\",Address=\"%@\",City=\"%@\",State=\"%@\",Email=\"%@\",Phone=\"%@\" WHERE ids=%@",details.firstNameString,details.lastNameString,details.dobString,details.addressString,details.cityString,details.stateString,details.emailString,details.PhoneString,details.ids];
const char *insert_stmt = [updateSQL UTF8String];
sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(@"Row updated");
}
else {
NSLog(@"Failed to update row");
}
sqlite3_finalize(statement);
sqlite3_close(database);
}
}
我更新代碼放在這裏
-(IBAction) update
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
savedData = [[DetailsClass alloc] init];
savedData.firstNameString = firstName.text;
savedData.lastNameString = lastName.text;
NSLog(@"last name is %@",savedData.lastNameString);
savedData.dobString = dob.text;
savedData.addressString = address.text;
savedData.cityString = city.text ;
NSLog(@"Changed city value is %@",savedData.cityString);
savedData.stateString = state.text;
savedData.emailString = email.text;
NSLog(@"Changes state value is %@",savedData.emailString);
savedData.PhoneString = phone.text;
NSLog(@"Phone no is %@",savedData.PhoneString);
savedData.ids = idString;
NSLog(@"details in id %@",savedData.ids);
[delegate.updateArray addObject:savedData];
[delegate updateData];
}
這會不會犯任何錯誤 如果我們使用了兩個不同的陣列保存和更新,將有什麼區別?
讓我知道問題在哪裏。謝謝!
你有沒有打開別處的那個數據庫的實例..也許像sqlite dbmanager – 2012-03-08 06:00:52
不......我打開任何實例。 – Kiran 2012-03-08 06:01:48