Writes an approval request object.

def WriteApprovalRequest(self, approval_request, cursor=None):
    """Writes an approval request object."""
    # Copy the approval_request to ensure we don't modify the source object.
    approval_request = approval_request.Copy()
    # Generate random approval id.
    approval_id_int = random.UInt64()

    grants = approval_request.grants
    approval_request.grants = None

    expiry_time = approval_request.expiration_time

    args = {
        "username_hash": mysql_utils.Hash(approval_request.requestor_username),
        "approval_type": int(approval_request.approval_type),
        "subject_id": approval_request.subject_id,
        "approval_id": approval_id_int,
        "expiration_time": mysql_utils.RDFDatetimeToTimestamp(expiry_time),
        "approval_request": approval_request.SerializeToString()
    }
    query = """
    INSERT INTO approval_request (username_hash, approval_type,
                                  subject_id, approval_id, expiration_time,
                                  approval_request)
    VALUES (%(username_hash)s, %(approval_type)s,
            %(subject_id)s, %(approval_id)s, FROM_UNIXTIME(%(expiration_time)s),
            %(approval_request)s)
    """
    cursor.execute(query, args)

    for grant in grants:
      self._GrantApproval(approval_request.requestor_username, approval_id_int,
                          grant.grantor_username, cursor)

    return _IntToApprovalID(approval_id_int)