sqlite3中使用XCode的断言失败,绑定问题?
大家好,我已经花了几个小时来解决这个错误。 我无法更新数据库,每当我尝试更新时,它都会崩溃 任何能帮忙的人都是最受欢迎的sqlite3中使用XCode的断言失败,绑定问题?,xcode,sqlite,Xcode,Sqlite,大家好,我已经花了几个小时来解决这个错误。 我无法更新数据库,每当我尝试更新时,它都会崩溃 任何能帮忙的人都是最受欢迎的 请温柔一点,因为我只是XCode的新手 我想你错过了以下句子中%@前后的单引号 换成这个 -(void)updatepw{ databaseName=@"bestfb.sqlite"; NSArray *documnetPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomai
请温柔一点,因为我只是XCode的新手 我想你错过了以下句子中%@前后的单引号 换成这个
-(void)updatepw{
databaseName=@"bestfb.sqlite";
NSArray *documnetPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documnetDir =[documnetPath objectAtIndex:0];
databasePath=[documnetDir stringByAppendingPathComponent:databaseName];
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSString *update = [[NSString alloc] initWithFormat:@"update staff set pword = %@ where staffID=1;", todb];
sqlite3_stmt *selectstmt;
const char *sql= (char *) update;
NSLog(@"new sql :%@", sql);
NSLog(@"values: %@", newpw.text);
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) ==SQLITE_OK){
NSLog(@"prepare failed");
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
else {
sqlite3_bind_text(selectstmt, 1, [todb UTF8String], -1, SQLITE_TRANSIENT);
NSLog(@"binding done");
}
int success1 = sqlite3_step(selectstmt);
if (success1 != SQLITE_DONE) {
NSAssert1(0, @"Error: failed to save priority with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_finalize(selectstmt);
}
sqlite3_close(database);
}
我已经这样做了,绑定成功了。但是,我的应用程序仍然崩溃。有什么想法吗(很抱歉,绑定未成功。语句准备失败。替换上述语句后,请清除所有目标并删除应用程序。然后重新安装。我找到了解决方案。代码没有问题,除了NSLog(@“new sql:%@”,sql);问题在于我不应该尝试记录字符。:)删除了该行,应用程序和更新顺利进行。
NSString *update = [[NSString alloc] initWithFormat:@"update staff set pword = '%@' where staffID=1;", todb];