Forum OpenACS Q&A: Re: Instructions on how to sort in the listbuilder - part II

Hi everybody,

I'm going to take my chance in this forum to point a possible bug in list builder. When you try to create a filter using the template::list::filter_where_clauses without the -and switch, the query has a formation problem. Instead of putting the where instruction before the clause, it's passing directly the clause, wich throws an error in the query. For example:

select * from my_table
[template::list::filter_where_clauses -name "list"]

Let's presume your where clause is something like:

" state = $state_var"

The final query will be:

select * from my_table
state = $state_var

The procedure makes the select to be broken if you don't have any other native where in your select. My way to fix it was to change the procedure in the list-procs.tcl file adding a -where switch to the procedure. It was somethnig like this:

ad_proc -public template::list::filter_where_clauses {
-name:required
-where:boolean
-and:boolean
} {
@param and Set this flag if you want the result to start with an 'and' if the list of where clauses returned is non-empty.
@param where
} {
# Get an upvar'd reference to list_properties
get_reference -name $name

if { [llength $list_properties(filter_where_clauses)] == 0 } {
return {}
}

set result {}
if { $and_p } {
append result "and "
}
#If you don't have a where in your query, insert one
if { $where_p } {
append result "where "
}

append result [join $list_properties(filter_where_clauses) "\n and "]

return $result
}

The final result after the fix for the above example will be:

select * from my_table
where state = $state_var