<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cursor(self):
 """ Get a cursor for the current connection. For internal use only. """

        cursor = self.mdr.cursor()
        with self.transaction():
            try:
                yield cursor
                if cursor.rowcount != -1:
                    self.last_row_count = cursor.rowcount
                self.last_row_id = getattr(cursor, 'lastrowid', None)
            except:
                self.last_row_count = None
                self.last_row_id = None
                _safe_close(cursor)
                raise