nodes: 0, module; 1, function_definition; 2, function_name:__remove_category; 3, parameters; 4, block; 5, identifier:self; 6, identifier:id; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, comment:"""move all activities to unsorted and remove category"""; 15, assignment; 16, assignment; 17, assignment; 18, call; 19, call; 20, call; 21, identifier:affected_query; 22, comment:"""
              SELECT id
                FROM facts
               WHERE activity_id in (SELECT id FROM activities where category_id=?)
          """; 23, identifier:affected_ids; 24, list_comprehension; 25, identifier:update; 26, string:"update activities set category_id = -1 where category_id = ?"; 27, attribute; 28, argument_list; 29, attribute; 30, argument_list; 31, attribute; 32, argument_list; 33, subscript; 34, for_in_clause; 35, identifier:self; 36, identifier:execute; 37, identifier:update; 38, tuple; 39, identifier:self; 40, identifier:execute; 41, string:"delete from categories where id = ?"; 42, tuple; 43, identifier:self; 44, identifier:__remove_index; 45, identifier:affected_ids; 46, identifier:res; 47, integer:0; 48, identifier:res; 49, call; 50, identifier:id; 51, identifier:id; 52, attribute; 53, argument_list; 54, identifier:self; 55, identifier:fetchall; 56, identifier:affected_query; 57, tuple; 58, identifier:id
code: def __remove_category(self, id):
          """move all activities to unsorted and remove category"""
  
          affected_query = """
              SELECT id
                FROM facts
               WHERE activity_id in (SELECT id FROM activities where category_id=?)
          """
          affected_ids = [res[0] for res in self.fetchall(affected_query, (id,))]
  
          update = "update activities set category_id = -1 where category_id = ?"
          self.execute(update, (id, ))
  
          self.execute("delete from categories where id = ?", (id, ))
  
          self.__remove_index(affected_ids)