raise ProgrammingError if cursor is closed