gpt4 book ai didi

iphone - 无法更新数据库ios

转载 作者:行者123 更新时间:2023-11-28 22:39:17 26 4
gpt4 key购买 nike

当我尝试更新我的数据库时,我无法更新它,名称和以前一样,没有改变。我应该怎么做才能让它起作用,因为我认为查询语句是正确的

这是我的代码:

//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);
}

最佳答案

用这个改变你的查询字符串

NSString*sql= [NSString stringWithFormat:@"UPDATE summary SET customer = '%@' WHERE key= '%@'", editCustomer,detailController.customerName];

这可能会解决你的问题

关于iphone - 无法更新数据库ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14998847/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com