0

为什么我不能将数据更新到 SQLite,即使它打印“是的”,请帮忙,这是我的代码,它是从 viewdidload 调用的:

    -(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);  



}    

它似乎通过了每一步,但我的数据根本没有改变。请提供任何帮助...我应该如何调用/编码才能在 SQLite 中插入/替换这些记录?

4

1 回答 1

-1
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);

并检查您的数据库连接是否正确打开

于 2012-06-22T05:14:10.990 回答