Skip Menu |
 

This queue is for tickets about the DBIx-SearchBuilder CPAN distribution.

Report information
The Basics
Id: 6450
Status: resolved
Priority: 0/
Queue: DBIx-SearchBuilder

People
Owner: Nobody in particular
Requestors: autrijus [...] autrijus.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Return-Path: <autrijus [...] autrijus.org>
X-Original-To: bug-dbix-searchbuilder [...] rt.cpan.org
Delivered-To: cpan-bug+dbix-searchbuilder [...] pallas.eruditorum.org
Received: from smtp2.apol.com.tw (smtp2.apol.com.tw [203.79.224.63]) by pallas.eruditorum.org (Postfix) with ESMTP id AFC8B84C337 for <bug-dbix-searchbuilder [...] rt.cpan.org>; Fri, 28 May 2004 05:47:21 -0400 (EDT)
Received: from mail.autrijus.org (210-85-16-204.cm.dynamic.apol.com.tw [210.85.16.204]) by smtp2.apol.com.tw (8.9.3/8.9.3) with ESMTP id RAA15955342 for <bug-dbix-searchbuilder [...] rt.cpan.org>; Fri, 28 May 2004 17:57:39 +0800 (CST)
Received: by mail.autrijus.org (Postfix, from userid 1000) id B79CC663F; Fri, 28 May 2004 17:48:27 +0800 (CST)
Date: Fri, 28 May 2004 17:48:27 +0800
From: Autrijus Tang <autrijus [...] autrijus.org>
To: bug-dbix-searchbuilder [...] rt.cpan.org
Subject: [PATCH] Make the Pg Join code the default
Message-Id: <20040528094827.GA80257 [...] aut.dyndns.org>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="huq684BweRXVnRxX"
Content-Disposition: inline
X-Copyright: Copyright 2003 by Autrijus Tang. All rights reserved.
X-Public-Key: http://autrijus.org/pubkey.asc
X-Notice: Forwarding of this mail prohibited without written consent.
User-Agent: Mutt/1.5.6i
Content-Length: 0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: us-ascii
Content-Length: 9291
Here is the promised diff. Note that since _BuildJoins is now moved to base, the extra check of ->can('_BuildJoins') is redundant, but the speed hit is miniscule so I did not microoptimize it away. Thanks, /Autrijus/ diff -dur DBIx-SearchBuilder-1.00_03.orig/SearchBuilder/Handle/Pg.pm DBIx-SearchBuilder-1.00_03/SearchBuilder/Handle/Pg.pm --- DBIx-SearchBuilder-1.00_03.orig/SearchBuilder/Handle/Pg.pm Fri May 28 12:00:10 2004 +++ DBIx-SearchBuilder-1.00_03/SearchBuilder/Handle/Pg.pm Fri May 28 17:34:17 2004 @@ -111,144 +111,6 @@ } -=head2 Join { Paramhash } - -Takes a paramhash of everything Searchbuildler::Record does + a parameter called 'SearchBuilder that contains a ref to a SearchBuilder object'. -This performs the join. - - -=cut - - -sub Join { - - my $self = shift; - my %args = ( - SearchBuilder => undef, - TYPE => 'normal', - FIELD1 => undef, - ALIAS1 => undef, - TABLE2 => undef, - FIELD2 => undef, - ALIAS2 => undef, - @_ - ); - - my $string; - - my $alias; - -#If we're handed in an ALIAS2, we need to go remove it from the Aliases array. -# Basically, if anyone generates an alias and then tries to use it in a join later, we want to be smart about -# creating joins, so we need to go rip it out of the old aliases table and drop it in as an explicit join - if ( $args{'ALIAS2'} ) { - - # this code is slow and wasteful, but it's clear. - my @aliases = @{ $args{'SearchBuilder'}->{'aliases'} }; - my @new_aliases; - foreach my $old_alias (@aliases) { - if ( $old_alias =~ /^(.*?) ($args{'ALIAS2'})$/ ) { - $args{'TABLE2'} = $1; - $alias = $2; - - } - else { - push @new_aliases, $old_alias; - } - } - # If we found an alias, great. let's just pull out the table and alias for the other item - unless ($alias) { - # if we can't do that, can we reverse the join and have it work? - my $a1 = $args{'ALIAS1'}; - my $f1 = $args{'FIELD1'}; - $args{'ALIAS1'} = $args{'ALIAS2'}; - $args{'FIELD1'} = $args{'FIELD2'}; - $args{'ALIAS2'} = $a1; - $args{'FIELD2'} = $f1; - - @aliases = @{ $args{'SearchBuilder'}->{'aliases'} }; - @new_aliases = (); - foreach my $old_alias (@aliases) { - if ( $old_alias =~ /^(.*?) ($args{'ALIAS2'})$/ ) { - $args{'TABLE2'} = $1; - $alias = $2; - - } - else { - push @new_aliases, $old_alias; - } - } - - } - - unless ($alias) { - return ( $self->SUPER::Join(%args) ); - } - if ($args{'ALIAS1'}) { - return ( $self->SUPER::Join(%args) ); - } - - $args{'SearchBuilder'}->{'aliases'} = \@new_aliases; - } - - else { - $alias = $args{'SearchBuilder'}->_GetAlias( $args{'TABLE2'} ); - - } - - if ( $args{'TYPE'} =~ /LEFT/i ) { - - $string = " LEFT JOIN " . $args{'TABLE2'} . " $alias "; - - } - else { - - $string = " JOIN " . $args{'TABLE2'} . " $alias "; - - } - $args{'SearchBuilder'}->{'left_joins'}{"$alias"}{'alias_string'} = $string; - $args{'SearchBuilder'}->{'left_joins'}{"$alias"}{'depends_on'} = $args{'ALIAS1'}; - $args{'SearchBuilder'}->{'left_joins'}{"$alias"}{'criteria'} { 'criterion' . $args{'SearchBuilder'}->{'criteria_count'}++ } = " $args{'ALIAS1'}.$args{'FIELD1'} = $alias.$args{'FIELD2'}"; - - return ($alias); -} - - - -# this code is all hacky and evil. but people desperately want _something_ and I'm -# super tired. refactoring gratefully appreciated. - -sub _BuildJoins { - my $self = shift; - my $sb = shift; - my %seen_aliases; - - $seen_aliases{'main'} = 1; - - my $join_clause =$sb->{'table'} . " main " ; - - my @keys = ( keys %{ $sb->{'left_joins'} } ); - - while ( my $join = shift @keys ) { - if ( $seen_aliases{ $sb->{'left_joins'}{$join}{'depends_on'} } ) { - $join_clause = "(" . $join_clause; - $join_clause .= $sb->{'left_joins'}{$join}{'alias_string'} . " ON ("; - $join_clause .= - join ( ') AND( ', values %{ $sb->{'left_joins'}{$join}{'criteria'} } - ); - $join_clause .= ")) "; - - $seen_aliases{$join} = 1; - } - else { - push ( @keys, $join ); - } - - } - return ( - join ( ", ", ($join_clause, @{ $sb->{'aliases'} }))) ; - -} # {{{ _MakeClauseCaseInsensitive =head2 _MakeClauseCaseInsensitive FIELD OPERATOR VALUE diff -dur DBIx-SearchBuilder-1.00_03.orig/SearchBuilder/Handle.pm DBIx-SearchBuilder-1.00_03/SearchBuilder/Handle.pm --- DBIx-SearchBuilder-1.00_03.orig/SearchBuilder/Handle.pm Fri May 28 12:00:10 2004 +++ DBIx-SearchBuilder-1.00_03/SearchBuilder/Handle.pm Fri May 28 17:36:46 2004 @@ -733,6 +733,99 @@ @_ ); + my $string; + + my $alias; + +#If we're handed in an ALIAS2, we need to go remove it from the Aliases array. +# Basically, if anyone generates an alias and then tries to use it in a join later, we want to be smart about +# creating joins, so we need to go rip it out of the old aliases table and drop it in as an explicit join + if ( $args{'ALIAS2'} ) { + + # this code is slow and wasteful, but it's clear. + my @aliases = @{ $args{'SearchBuilder'}->{'aliases'} }; + my @new_aliases; + foreach my $old_alias (@aliases) { + if ( $old_alias =~ /^(.*?) ($args{'ALIAS2'})$/ ) { + $args{'TABLE2'} = $1; + $alias = $2; + + } + else { + push @new_aliases, $old_alias; + } + } + # If we found an alias, great. let's just pull out the table and alias for the other item + unless ($alias) { + # if we can't do that, can we reverse the join and have it work? + my $a1 = $args{'ALIAS1'}; + my $f1 = $args{'FIELD1'}; + $args{'ALIAS1'} = $args{'ALIAS2'}; + $args{'FIELD1'} = $args{'FIELD2'}; + $args{'ALIAS2'} = $a1; + $args{'FIELD2'} = $f1; + + @aliases = @{ $args{'SearchBuilder'}->{'aliases'} }; + @new_aliases = (); + foreach my $old_alias (@aliases) { + if ( $old_alias =~ /^(.*?) ($args{'ALIAS2'})$/ ) { + $args{'TABLE2'} = $1; + $alias = $2; + + } + else { + push @new_aliases, $old_alias; + } + } + + } + + unless ($alias) { + return ( $self->_NormalJoin(%args) ); + } + if ($args{'ALIAS1'}) { + return ( $self->_NormalJoin(%args) ); + } + + $args{'SearchBuilder'}->{'aliases'} = \@new_aliases; + } + + else { + $alias = $args{'SearchBuilder'}->_GetAlias( $args{'TABLE2'} ); + + } + + if ( $args{'TYPE'} =~ /LEFT/i ) { + + $string = " LEFT JOIN " . $args{'TABLE2'} . " $alias "; + + } + else { + + $string = " JOIN " . $args{'TABLE2'} . " $alias "; + + } + $args{'SearchBuilder'}->{'left_joins'}{"$alias"}{'alias_string'} = $string; + $args{'SearchBuilder'}->{'left_joins'}{"$alias"}{'depends_on'} = $args{'ALIAS1'}; + $args{'SearchBuilder'}->{'left_joins'}{"$alias"}{'criteria'} { 'criterion' . $args{'SearchBuilder'}->{'criteria_count'}++ } = " $args{'ALIAS1'}.$args{'FIELD1'} = $alias.$args{'FIELD2'}"; + + return ($alias); +} + +sub _NormalJoin { + + my $self = shift; + my %args = ( + SearchBuilder => undef, + TYPE => 'normal', + FIELD1 => undef, + ALIAS1 => undef, + TABLE2 => undef, + FIELD2 => undef, + ALIAS2 => undef, + @_ + ); + my $sb = $args{'SearchBuilder'}; @@ -757,6 +850,43 @@ @_ ); } +} + +# this code is all hacky and evil. but people desperately want _something_ and I'm +# super tired. refactoring gratefully appreciated. + +sub _BuildJoins { + my $self = shift; + my $sb = shift; + my %seen_aliases; + + $seen_aliases{'main'} = 1; + + my $join_clause =$sb->{'table'} . " main " ; + + my @keys = ( keys %{ $sb->{'left_joins'} } ); + my %seen; + + while ( my $join = shift @keys ) { + if ( $seen_aliases{ $sb->{'left_joins'}{$join}{'depends_on'} } ) { + $join_clause = "(" . $join_clause; + $join_clause .= $sb->{'left_joins'}{$join}{'alias_string'} . " ON ("; + $join_clause .= + join ( ') AND( ', values %{ $sb->{'left_joins'}{$join}{'criteria'} } + ); + $join_clause .= ")) "; + + $seen_aliases{$join} = 1; + } + else { + push ( @keys, $join ); + die "Unsatisfied dependency chain in Joins@keys" if $seen{"@keys"}++; + } + + } + return ( + join ( ", ", ($join_clause, @{ $sb->{'aliases'} }))) ; + } # }}}
Content-Type: application/pgp-signature
Content-Disposition: inline
Content-Length: 187
Download (untitled)
application/pgp-signature 187b

Message body not shown because it is not plain text.

Return-Path: <jesse [...] pallas.eruditorum.org>
X-Original-To: bug-DBIx-SearchBuilder [...] rt.cpan.org
Delivered-To: cpan-bug+dbix-searchbuilder [...] pallas.eruditorum.org
Received: by pallas.eruditorum.org (Postfix, from userid 1000) id 493AA84C0E6; Fri, 28 May 2004 13:42:33 -0400 (EDT)
Date: Fri, 28 May 2004 13:42:33 -0400
From: Jesse <jesse [...] fsck.com>
To: Autrijus Tang via RT <bug-DBIx-SearchBuilder [...] rt.cpan.org>
Subject: Re: [cpan #6450] [PATCH] Make the Pg Join code the default
Message-Id: <20040528174233.GV16435 [...] pallas.eruditorum.org>
References: <rt-6450-19355.7.85371536369851 [...] cpan.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <rt-6450-19355.7.85371536369851 [...] cpan.org>
User-Agent: Mutt/1.5.5.1+cvs20040105i
RT-Send-Cc:
X-RT-Original-Encoding: us-ascii
Content-Length: 640
Download (untitled) / with headers
text/plain 640b
On Fri, May 28, 2004 at 05:47:27AM -0400, Autrijus Tang via RT wrote: Show quoted text
> > This message about DBIx-SearchBuilder was sent to you by autrijus@autrijus.org <autrijus@autrijus.org> via rt.cpan.org > > Full context and any attached attachments can be found at: > <URL: https://rt.cpan.org/Ticket/Display.html?id=6450 > > > Here is the promised diff. Note that since _BuildJoins is now > moved to base, the extra check of ->can('_BuildJoins') is redundant, > but the speed hit is miniscule so I did not microoptimize it away.
Does this patch just move code around or does it also fix the possible endless loop? Show quoted text
> Thanks, > /Autrijus/ >


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.