uitextview中的sqlite3更新文本

时间:2010-03-22 03:53:40

标签: iphone sqlite uitextview detailsview

我已经准备好了更新的sqlite语句..但是我很困惑从uitextview抓取文本并更新它...我匆匆使用uibutton更新它。如何在创建sql语句后继续?有点失落......一个新的解决方案是欣赏..

- (void) saveAllData {
    if(isDirty) {
        if(updateStmt == nil) {
            const char *sql = "update Snap Set snapTitle = ?, snapDesc = ?, Where snapID = ?";
            if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
                NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));
            }
            sqlite3_bind_text(updateStmt, 1, [snapTitle UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(updateStmt, 2, [snapDescription UTF8String], -2, SQLITE_TRANSIENT);
            sqlite3_bind_int(updateStmt, 3, snapID);
            if(SQLITE_DONE != sqlite3_step(updateStmt))
                NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
                sqlite3_reset(updateStmt);
                isDirty = NO;
            }

        //Reclaim all memory here.
        [snapTitle release];
        snapTitle = nil;
        [snapDescription release];
        snapDescription = nil;

        //isDetailViewHydrated = NO;
    }
}

1 个答案:

答案 0 :(得分:0)

而不是sqlite3_reset(updateStmt)我使用sqlite3_finalize(updateStmt),代码运行正常。