'Returns a string of the query last executed by the given cursor, with
placeholders replaced with actual values.
`sql` is the raw query containing placeholders, and `params` is the
sequence of parameters. These are used by default, but this method
exists for database backends to provide a better implementation
according to their own quoting schemes.'

def last_executed_query(self, cursor, sql, params):

    from django.utils.encoding import force_text
    to_unicode = (lambda s: force_text(s, strings_only=True, errors='replace'))
    if isinstance(params, (list, tuple)):
        u_params = tuple([to_unicode(val) for val in params])
    else:
        u_params = dict([(to_unicode(k), to_unicode(v)) for (k, v) in params.items()])
    return (force_text(sql) % u_params)
