A prison officer who was drunk, complained about his wife to a barmaid, before sexually assaulting her, a court heard.