'Return the SQL version of the where clause and the value to be
substituted in. Return \'\', [] if this node matches everything,
None, [] if this node is empty, and raise EmptyResultSet if this
node can\'t match anything.'

def as_sql(self, compiler, connection):

    result = []
    result_params = []
    if (self.connector == AND):
        (full_needed, empty_needed) = (len(self.children), 1)
    else:
        (full_needed, empty_needed) = (1, len(self.children))
    for child in self.children:
        try:
            (sql, params) = compiler.compile(child)
        except EmptyResultSet:
            empty_needed -= 1
        else:
            if sql:
                result.append(sql)
                result_params.extend(params)
            else:
                full_needed -= 1
        if (empty_needed == 0):
            if self.negated:
                return ('', [])
            else:
                raise EmptyResultSet
        if (full_needed == 0):
            if self.negated:
                raise EmptyResultSet
            else:
                return ('', [])
    conn = ('    %s    ' % self.connector)
    sql_string = conn.join(result)
    if sql_string:
        if self.negated:
            sql_string = ('NOT    (%s)' % sql_string)
        elif (len(result) > 1):
            sql_string = ('(%s)' % sql_string)
    return (sql_string, result_params)
