Fix bug in item_history database function