NAME
Class::DBI::SearchGenerator - construct SQL for searches
DESCRIPTION
This module provides an interface for generating SQL for Class::DBI searches. It provides methods for manipulating the column/value pairs and other options passed to search() methods, and can give you back either the resulting objects, or a raw sth for your processing.
CONSTRUCTOR
new
my $generator = Class::DBI::SearchGenerator->new(
$cdbi, $search_type, @args
);
This constructs a new SearchGenerator object. $cdbi is the Class::DBI subclass we will be serching, $search_type is the search keyword ("=", "LIKE" etc), and @args are the options passed to search by the user.
METHODS
results
my @objects = $generator->results;
my @iterator = $generator->results;
This will return the objects resulting from running the search.
sth
This will return the raw statement handle suitable for manipulating yourself, created by interpolating sql_fragment() into sql_Retrieve.
ACCESSORS
There are a variety of methods available for you to override or manipulate if you are wanting to change the way searches work:
args
my @args = $generator->args;
This will return the key/value pairs passed to search, after stripping off any options also passed. This is a list, rather than a hash, as you may be passing multiple criteria on the same column.
option
my $value = $generator->option("order_by");
Returns any value passed through for the given option.
cdbi
my $class = $generator->cdbi;
The Class::DBI subclass which we are searching.
cols / vals
my @cols = $generator->cols;
my @vals = $generator->vals;
This provides two unzipped lists from the key/value pairs passed by the user into the search() function. cols() returns a list of Class::DBI::Column objects, and vals() returns a list of (deflated) values. vals() may contain undefs for NULL searches.
sql_fragment
This returns the fragment of SQL that will be interpolated into SELECT __ESSENTIAL__ FROM __TABLE__ WHERE %s