Difference between revisions of "Freeside:3:Documentation:Developer/FS/Query"

From Freeside
Jump to: navigation, search
(Edit via perl MediaWiki framework (1.13))
 
(No difference)

Latest revision as of 09:34, 21 July 2015

NAME

FS::Query - A thin wrapper around qsearch argument hashes.

DESCRIPTION

This module exists because we pass qsearch argument lists around a lot, and add new joins or WHERE expressions in several stages, and I got tired of doing this:

 my $andwhere = "mycolumn IN('perl','python','javascript')";
 if ( ($search->{hashref} and keys( %{$search->{hashref}} ))
      or $search->{extra_sql} =~ /^\s*WHERE/ ) {
   $search->{extra_sql} .= " AND $andwhere";
 } else {
   $search->{extra_sql} = " WHERE $andwhere ";
 }

and then having it fail under some conditions if it's done wrong (as the above example is, obviously).

We may eventually switch over to SQL::Abstract or something for this, but for now it's a couple of crude manipulations and a wrapper to qsearch.

METHODS

new HASHREF
Turns HASHREF (a qsearch argument list) into an FS::Query object. None of the params are really required, but you should at least supply table.
In the Future this may do a lot more stuff.
clone
Returns another object that's a copy of this one.
and_where EXPR
Adds a constraint to the WHERE clause of the query. All other constraints in the WHERE clause should be joined with AND already; if not, they should be grouped with parentheses.
qsearch
Runs the query and returns all results.
qsearchs
Runs the query and returns only one result.