2011-05-05 45 views

回答

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);  
} 
相关问题