'Run the query against the database and returns the result(s). The
return value is a single data item if result_type is SINGLE, or an
iterator over the results if the result_type is MULTI.
result_type is either MULTI (use fetchmany() to retrieve all rows),
SINGLE (only retrieve a single row), or None. In this last case, the
cursor is returned if any query is executed, since it\'s used by
subclasses such as InsertQuery). It\'s possible, however, that no query
is needed, as the filters describe an empty set. In that case, None is
returned, to avoid any unnecessary database interaction.'

def execute_sql(self, result_type=MULTI):

    try:
        (sql, params) = self.as_sql()
        if (not sql):
            raise EmptyResultSet
    except EmptyResultSet:
        if (result_type == MULTI):
            return iter([])
        else:
            return
    cursor = self.connection.cursor()
    cursor.execute(sql, params)
    if (not result_type):
        return cursor
    if (result_type == SINGLE):
        if self.query.ordering_aliases:
            return cursor.fetchone()[:(- len(self.query.ordering_aliases))]
        return cursor.fetchone()
    if self.query.ordering_aliases:
        result = order_modified_iter(cursor, len(self.query.ordering_aliases), self.connection.features.empty_fetchmany_value)
    else:
        result = iter((lambda : cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)), self.connection.features.empty_fetchmany_value)
    if (not self.connection.features.can_use_chunked_reads):
        return list(result)
    return result
