def METHOD_NAME(self):
    from freppledb.common.middleware import _thread_locals
    req = getattr(_thread_locals, "request", None)
    if req:
        db = getattr(req, "database", DEFAULT_DB_ALIAS)
    else:
        db = getattr(_thread_locals, "database", DEFAULT_DB_ALIAS)
    SQLColumn.objects.filter(report=self).using(db).delete()
    if self.sql:
        conn = None
        try:
            conn = create_connection(db)
            with conn.cursor() as cursor:
                sqlrole = settings.DATABASES[db].get("SQL_ROLE", "report_role")
                if sqlrole:
                    cursor.execute("set role %s" % (sqlrole,))
                # The query is wrapped in a dummy filter, to avoid executing the
                # inner real query. It still generates the list of all columns.
                cursor.execute("select * from (%s) as Q where false" % self.sql)
                if self.id:
                    cols = []
                    seq = 1
                    for f in cursor.description:
                        if f[0] in cols:
                            raise Exception("Duplicate column name '%s'" % f[0])
                        cols.append(f[0])
                        if f[1] == 1700:
                            fmt = "number"
                        elif f[1] == 1184:
                            fmt = "datetime"
                        elif f[1] in (23, 20):
                            fmt = "integer"
                        elif f[1] == 1186:
                            fmt = "duration"
                        elif f[1] == 1043:
                            fmt = "text"
                        else:
                            fmt = "character"
                        SQLColumn(
                            report=self, sequence=seq, name=f[0], format=fmt
                        ).save(using=db)
                        seq += 1
        finally:
            if conn:
                conn.close()