'Create the SQL for this query. Return the SQL string and list of
parameters.'

def as_sql(self):

    self.pre_sql_setup()
    if (not self.query.values):
        return ('', ())
    qn = self.quote_name_unless_alias
    (values, update_params) = ([], [])
    for (field, model, val) in self.query.values:
        if hasattr(val, 'resolve_expression'):
            val = val.resolve_expression(self.query, allow_joins=False, for_save=True)
            if val.contains_aggregate:
                raise FieldError('Aggregate    functions    are    not    allowed    in    this    query')
        elif hasattr(val, 'prepare_database_save'):
            if field.remote_field:
                val = field.get_db_prep_save(val.prepare_database_save(field), connection=self.connection)
            else:
                raise TypeError(('Tried    to    update    field    %s    with    a    model    instance,    %r.    Use    a    value    compatible    with    %s.' % (field, val, field.__class__.__name__)))
        else:
            val = field.get_db_prep_save(val, connection=self.connection)
        if hasattr(field, 'get_placeholder'):
            placeholder = field.get_placeholder(val, self, self.connection)
        else:
            placeholder = '%s'
        name = field.column
        if hasattr(val, 'as_sql'):
            (sql, params) = self.compile(val)
            values.append(('%s    =    %s' % (qn(name), (placeholder % sql))))
            update_params.extend(params)
        elif (val is not None):
            values.append(('%s    =    %s' % (qn(name), placeholder)))
            update_params.append(val)
        else:
            values.append(('%s    =    NULL' % qn(name)))
    table = self.query.base_table
    result = [('UPDATE    %s    SET' % qn(table)), ',    '.join(values)]
    (where, params) = self.compile(self.query.where)
    if where:
        result.append(('WHERE    %s' % where))
    return ('    '.join(result), tuple((update_params + params)))
