ad_order_by_from_sort_spec

one of the documented procedures in this installation of the ACS
Usage:
ad_order_by_from_sort_spec   sort_by   tabledef
What it does:
Takes a sort_by spec, and translates it into into an "order by" clause with each sort_by key dictated by the sort info in tabledef
Defined in: /web/philip/packages/acs-core/table-display-procs.tcl

Source code:


    set order_by_clause {}

    foreach sort_key_spec [split $sort_by ","] {
        if { [regexp {^([A-Za-z_]+)(\*?)$} $sort_key_spec match sort_key reverse] } {
            # if there's a "*" after the key, we want to reverse the usual order
            foreach order_spec $tabledef {
                if { $sort_key == [lindex $order_spec 0] } {

                    if { $reverse == "*" } {
                        set order "desc"
                    } else {
                        set order "asc"
                    }
                    
                    if { $order_by_clause == "" } {
                        append order_by_clause "\norder by "
                    } else {
                        append order_by_clause ", "
                    }

                    # tack on the order by clause 
                    if {![empty_string_p [lindex $order_spec 2]]} {
                        append order_by_clause "[subst [lindex $order_spec 2]]"
                    } else { 
                        append order_by_clause "$sort_key $order"
                    }
                    break
                }
            }
        }
    }
    return $order_by_clause


philg@mit.edu