データベースを更新しようとしても更新できません。名前は以前と同じままで、変更されませんでした。クエリステートメントは正しいと思うので、機能させるにはどうすればよいですか
これは私のコードです:
//file path to database
-(NSString*)filePath {
NSArray*paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:0]stringByAppendingPathComponent:@"bp.sql"];
}
//open database
-(void)openDB {
if(sqlite3_open([[self filePath]UTF8String], &db) !=SQLITE_OK) {
sqlite3_close(db);
NSAssert(0, @"Databese failed to open");
}
else {
NSLog(@"database opemed");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)edit:(id)sender {
bool text = true;
editCodeOne = code1Edit.text;
editCodeTwo = code2Edit.text;
editCustomer = customerEdit.text;
editDate = [NSDate date];
if ([code1Edit.text isEqualToString:@""] && [code2Edit.text isEqualToString:@""] && [customerEdit.text isEqualToString:@""]) {
text =false;
}
if (text ==false) {
UIAlertView*alert = [[UIAlertView alloc] initWithTitle:@"Edit failed" message:@"The data has not changed " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
if(text == true){
NSString*sql= [NSString stringWithFormat:@"REPLACE summary SET customer = \"'%@'\" WHERE key= \"%@\"", editCustomer,detailController.customerName];
const char* query_stmt = [sql UTF8String];
sqlite3_stmt*statement;
if( sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL )){
if (sqlite3_step(statement)!= SQLITE_UPDATE) {
sqlite3_close(db);
NSAssert(0, @"Could not update table");
}
else {
NSLog(@"table updated");
code1Edit.text = @"";
code2Edit.text = @"";
customerEdit.text = @"";
}
}
sqlite3_finalize(statement);
}