code: def cursor(self):
          
          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
docs: Get a cursor for the current connection. For internal use only.