Re: search() without search criteria

[prev] [thread] [next] [Date index for 2005/04/29]

From: Matt S Trout
Subject: Re: search() without search criteria
Date: 13:18 on 29 Apr 2005
On Fri, Apr 29, 2005 at 01:36:59PM +0100, Will Hawes wrote:
> I need to implement paging for potentially large result sets using CDBI. The pager should be usable for any CDBI subclass, so column names will not be known beforehand. Search criteria are optional. In order to keep things as efficient as possible I would like to make sure that only the number of records required for a single page will be returned by the query, so I would like to use search() and pass attributes e.g. "rows", "offset", etc as the second argument.
> 
> This works fine when search criteria are specified:
> 
> $class->search(column1 => value, {rows => 10});
> 
> When there are no search criteria specified however:
> 
> $class->search({}, {rows => 10});
> 
> search() tries to execute a query like this:
> 
> "SELECT <columns> FROM <table> WHERE"
> 
> which fails, because there is nothing after WHERE.
> 
> I'm aware there are probably workarounds - using retrieve_all() to return an iterator is one that springs to mind, a custom constructor is another - but I want to avoid returning whole result sets into memory or, worse, writing custom SQL.
> 
> I'd like to hear opinions regarding a patch to Class::DBI so that search() accepts an empty hash as the first argument. This would allow order_by, limit, etc to be applied to the whole result set rather than having to use search criteria too.

Have a look at chansen's http://search.cpan.org/dist/Catalyst-Model-CDBI-Sweet/

Next release will apparently remove the Catalyst dependency, and add a
retrieve_all with order and paging. In the meantime, you can do a search()
without conditions by defining a column 1 and doing search({ 1 => 1 } ...)

        -- 
            Matt S Trout            Brag sheet:    http://trout.me.uk/services.html
LAMP, Infrastructure        Contact:       services@xxxxx.xx.xx
   and Automation
     specialist                                       Do it once. Do it right.

(message missing)

search() without search criteria
Will Hawes 12:36 on 29 Apr 2005

Re: search() without search criteria
Matt S Trout 13:18 on 29 Apr 2005

Re: search() without search criteria
Daniel Wijnands 14:06 on 29 Apr 2005

Re: search() without search criteria
Perrin Harkins 14:25 on 29 Apr 2005

Re: search() without search criteria
Will Hawes 16:53 on 29 Apr 2005

Re: search() without search criteria
Tony Bowden 18:38 on 29 Apr 2005

Re: search() without search criteria
Matt S Trout 19:38 on 29 Apr 2005

Re: search() without search criteria
Will Hawes 20:19 on 29 Apr 2005

Re: search() without search criteria
Tony Bowden 22:48 on 29 Apr 2005

Re: search() without search criteria
Perrin Harkins 16:40 on 30 Apr 2005

Re: search() without search criteria
David Baird 14:31 on 29 Apr 2005

Re: search() without search criteria
Peter Speltz 19:11 on 29 Apr 2005

Re: search() without search criteria
Tony Bowden 22:52 on 29 Apr 2005

Re: search() without search criteria
Will Hawes 12:13 on 30 Apr 2005

Re: search() without search criteria
Tony Bowden 12:19 on 30 Apr 2005

Re: search() without search criteria
merlyn (Randal L. Schwartz) 15:44 on 30 Apr 2005

Re: search() without search criteria
Will Hawes 17:45 on 30 Apr 2005

Re: search() without search criteria
Tony Bowden 10:27 on 01 May 2005

Re: search() without search criteria
Will Hawes 14:13 on 01 May 2005

Generated at 10:24 on 04 May 2005 by mariachi v0.52