'Build the DELETE query to be executed.'

def _BuildDelete(self, subject, attribute=None, timestamp=None):

    subjects_q = {'query': 'DELETE    subjects    FROM    subjects    WHERE    hash=unhex(md5(%s))', 'args': [subject]}
    aff4_q = {'query': 'DELETE    aff4    FROM    aff4    WHERE    subject_hash=unhex(md5(%s))', 'args': [subject]}
    locks_q = {'query': 'DELETE    locks    FROM    locks    WHERE    subject_hash=unhex(md5(%s))', 'args': [subject]}
    if attribute:
        aff4_q['query'] += '    AND    attribute_hash=unhex(md5(%s))'
        aff4_q['args'].append(attribute)
        if isinstance(timestamp, (tuple, list)):
            aff4_q['query'] += '    AND    aff4.timestamp    >=    %s    AND    aff4.timestamp    <=    %s'
            aff4_q['args'].append(int(timestamp[0]))
            aff4_q['args'].append(int(timestamp[1]))
        attributes_q = {'query': 'DELETE    attributes    FROM    attributes    LEFT    JOIN    aff4    ON    aff4.attribute_hash=attributes.hash    WHERE    attributes.hash=unhex(md5(%s))    AND    aff4.attribute_hash    IS    NULL', 'args': [attribute]}
        return [aff4_q, attributes_q]
    return [aff4_q, locks_q, subjects_q]
