Iphone 在SQLite中插入/替换数据
为什么我不能将数据更新到SQLite即使它打印“是是”,请帮助,这里是我的代码,它从viewdidload调用:Iphone 在SQLite中插入/替换数据,iphone,sqlite,insert,replace,Iphone,Sqlite,Insert,Replace,为什么我不能将数据更新到SQLite即使它打印“是是”,请帮助,这里是我的代码,它从viewdidload调用: -(void)updateData{ CryptTestAppDelegate *delegate=(CryptTestAppDelegate *)[[UIApplication sharedApplication] delegate]; sqlite3_stmt *stmt=nil; NSString *dd = @"testing";
-(void)updateData{
CryptTestAppDelegate *delegate=(CryptTestAppDelegate *)[[UIApplication sharedApplication] delegate];
sqlite3_stmt *stmt=nil;
NSString *dd = @"testing";
const char *sql = "Update ProvPuzz set desc2=?";
sqlite3_prepare_v2(delegate.db, sql, 1, &stmt, NULL);
sqlite3_bind_text(stmt, 1, [dd UTF8String], -1, SQLITE_TRANSIENT);
if(sqlite3_step(stmt)){
NSLog(@"yes yes");
}else{
NSLog(@"no no");
}
sqlite3_finalize(stmt);
sqlite3_close(delegate.db);
}
它似乎通过了每一步,但我的数据没有任何变化。需要帮忙吗。。。
我应该如何调用/code才能在SQLite中插入/替换这些记录
NSString *UpdateSql = [NSString stringWithFormat:@"Update ProvPuzz set desc2 = something"];
const char *sqlStatement = [UpdateSql UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(filesDB, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
if(sqlite3_step(compiledStatement) == SQLITE_DONE)
{
sqlite3_reset(compiledStatement);
}
}
// Release the compiled statement from memory
sqlite3_reset(compiledStatement);
sqlite3_finalize(compiledStatement);
sqlite3_close(filesDB);
还要检查数据库连接是否正确打开我确信您正在尝试写入应用程序主捆绑包中的数据库文件。您无法写入主捆绑包。那么我可以将数据库放在哪里(什么位置?)到Documents目录中。它运行时没有任何问题,但DB没有任何更改。关于数据库位置的任何建议都不能放在同一个应用程序文件夹中吗?我现在知道,实际上数据已经更改,但这只是我的错误,没有将数据与留在模拟器文件夹中的真实数据库进行检查。谢谢