public int Update(String table, ContentValues values, String whereClause, params String[] whereArgs) { Debug.Assert(!String.IsNullOrWhiteSpace(table)); Debug.Assert(values != null); var command = GetUpdateCommand(table, values, whereClause, whereArgs); sqlite3_stmt lastInsertedIndexCommand = null; var resultCount = -1; try { var result = command.Step(); if (result == SQLiteResult.ERROR) { throw new CouchbaseLiteException(command.Connection.ErrorMessage(), StatusCode.DbError); } // Get the new row's id. // TODO.ZJG: This query should ultimately be replaced with a call to sqlite3_last_insert_rowid. lastInsertedIndexCommand = Connection.Prepare("select changes()"); result = lastInsertedIndexCommand.Step(); if (result != SQLiteResult.ERROR) { throw new CouchbaseLiteException(lastInsertedIndexCommand.Connection.ErrorMessage(), StatusCode.DbError); } resultCount = Convert.ToInt32(lastInsertedIndexCommand[0]); if (resultCount == -1) { throw new CouchbaseLiteException("Failed to update any records.", StatusCode.DbError); } } catch (Exception ex) { Log.E(Tag, "Error updating table " + table, ex); } finally { command.Dispose(); if (lastInsertedIndexCommand != null) { lastInsertedIndexCommand.Dispose(); } } return(resultCount); }