如何在obj c中使用sqlite更新表中的数据

时间:2011-05-05 08:46:10

标签: iphone objective-c sqlite

每个人都

任何人都可以建议我在sqlite数据库中显示更新表的一个很好的教程

1 个答案:

答案 0 :(得分:1)

使用以下命令打开您的数据库:

sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK;

更新行:

@synchronized(sqlLock]) {
    // Setup the SQL Statement and compile it for faster access
    const char *sqlStatement = [[NSString stringWithFormat:@"UPDATE TABLE Set Text = ? where ID = '%@'",objectID] UTF8String];
    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {     

        sqlite3_bind_text(compiledStatement, 1, [text UTF8String], -1, SQLITE_TRANSIENT);

        if(SQLITE_DONE != sqlite3_step(compiledStatement))
            NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));

        sqlite3_reset(compiledStatement);
    }
    // Release the compiled statement from memory
    sqlite3_finalize(compiledStatement);    
}