Re: Maximum results to return from query



On Mon, Dec 05, 2005 at 07:44:53PM +0100, Olav Vitters wrote:
> On Mon, Dec 05, 2005 at 07:25:49AM -0700, Elijah Newren wrote:
> > Sounds like it'd also be a good idea, but I really do think we should
> > also special case an empty query and make it return
> > nothing--especially since we have caused it so many times ourselves.
> 
> I was able to implement this. buglist.cgi uses Bugzilla/Search.pm to
> generate the SQL (but not execute). This SQL will have a '1 = 1' in the
> WHERE part. This '1 = 1' could still be there if the query somehow was
> using HAVING instead, so the if-statement currently reads:
>  if ($query =~ / 1 = 1/ && $query !~ /HAVING/) {
> 
> The WHERE can have some stuff to show restricted bugs, so above was the
> best option I could think of... somewhat hackish, but oh well :-)

To explain further:
Bugzilla/Search.pm will know when there isn't anything for the WHERE
part of the SQL. E.g. when the user requested
  http://bugzilla.gnome.org/buglist.cgi?bug_id=
(Bugzilla will not add a bugs.bug_id IS NULL)

but also:
  http://bugzilla.gnome.org/buglist.cgi?id=163163
(id isn't a valid query field)

Only when Bugzilla doesn't have anything for the WHERE part it will
do a 'WHERE 1 = 1'. Bugzilla does this because it optionally adds some
WHERE parts if the user was logged in (WHERE 1=1 $login_stuff_sql). If
the user is logged out the WHERE would be: "WHERE 1=1". Bugzilla could
only include the WHERE part if the user was logged in... but it
fortunately does not.

The HAVING is only added if the SQL needs it.

In short, it checks if the resulting SQL has a valid WHERE or a valid
HAVING statement.

-- 
Regards,
Olav



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]