[Bps-public-commit] dbix-searchbuilder branch, master, updated. 1.63_01-22-gc177d8a

Alex Vandiver alexmv at bestpractical.com
Fri Mar 29 20:27:37 EDT 2013


The branch, master has been updated
       via  c177d8a3bc32410f3c36010ece7261379aebeb88 (commit)
       via  fcc9099bdde82c8ca323c10420f6021ca4bf6f48 (commit)
       via  c377cfadcb01cb9622c5925f0bbfd64ccfae9836 (commit)
       via  c7178fa1e26861d119792623c508c5abc10feefa (commit)
       via  1942aea26b1b3a6c343867e982264fc1bb5451c8 (commit)
       via  043abf1292302b5e43eaa9fc278db54db2da82d6 (commit)
       via  a3fc5bf80e90331b2ea4978a76799cda094ff094 (commit)
       via  b214830b2f3abbb5a90c79a92e43c285bd4f4c10 (commit)
       via  4d26f383e9ea413e261ef9862aae5ea2e4131484 (commit)
       via  0670a12730da1d0af0d2a7b81bb143235a83b04a (commit)
       via  6c6304130ba92bb6f9c9ed879a7553afb50c1ea4 (commit)
       via  73740d1d1711da8498e15f14f5a7e16c9da2450e (commit)
       via  e87defa5c1d15e5811bc4c9c52f833b9c71175d0 (commit)
       via  93a596817d088dbc61f74f9d0aaff0301b22b472 (commit)
       via  09abefdd351783215ef0aa8b737c77da16cbcaf1 (commit)
       via  7de45176471c8781edf3809c890a0acdf53d6143 (commit)
       via  d690a13d033a827bdf9d639bb18cf1e0860a6841 (commit)
       via  88e8b75906eb0d0d2cc1c11d8b9a38274f27f285 (commit)
       via  0bdd520d41c29eded232adf6382e6b60efaf0304 (commit)
       via  b6161ea45e4261b38c440020b74d7b4c5c4e72f5 (commit)
       via  4a26e2d31f82051d3071f8d2e5f520fa7a0015c1 (commit)
       via  6c248ed069029cf82ea073ec2c4adf4bdfffd03f (commit)
      from  2caf4afb765cf181a8200b0bae723a527ffab3c8 (commit)

Summary of changes:
 lib/DBIx/SearchBuilder.pm | 233 ++++++++++++++++------------
 t/01searches.t            |  30 +++-
 t/02searches_function.t   | 377 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 544 insertions(+), 96 deletions(-)
 create mode 100644 t/02searches_function.t

- Log -----------------------------------------------------------------
commit c177d8a3bc32410f3c36010ece7261379aebeb88
Merge: 2caf4af fcc9099
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Mar 29 20:26:48 2013 -0400

    Merge branch 'functions-in-searches'
    
    Conflicts:
    	lib/DBIx/SearchBuilder.pm
    	t/01searches.t

diff --cc lib/DBIx/SearchBuilder.pm
index 6c87366,eeb94e4..c75f42b
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@@ -849,35 -840,15 +853,42 @@@ sub Limit 
          elsif ( $args{'OPERATOR'} =~ /ENDSWITH/i ) {
              $args{'VALUE'}    = "%" . $args{'VALUE'};
          }
 +        elsif ( $args{'OPERATOR'} =~ /\bIN$/i ) {
 +            if ( blessed $args{'VALUE'} && $args{'VALUE'}->isa(__PACKAGE__) ) {
 +                # if no columns selected then select id
 +                local $args{'VALUE'}{'columns'} = $args{'VALUE'}{'columns'};
 +                unless ( $args{'VALUE'}{'columns'} ) {
 +                    $args{'VALUE'}->Column( FIELD => 'id' );
 +                } elsif ( @{ $args{'VALUE'}{'columns'} } > 1 ) {
 +                    warn "Collection in '$args{OPERATOR}' with more than one column selected, using first";
 +                    splice @{ $args{'VALUE'}{'columns'} }, 1;
 +                }
 +                $args{'VALUE'} = '('. $args{'VALUE'}->BuildSelectQuery .')';
 +                $args{'QUOTEVALUE'} = 0;
 +            }
 +            elsif ( ref $args{'VALUE'} ) {
 +                if ( $args{'QUOTEVALUE'} ) {
 +                    my $dbh = $self->_Handle->dbh;
 +                    $args{'VALUE'} = join ', ', map $dbh->quote( $_ ), @{ $args{'VALUE'} };
 +                } else {
 +                    $args{'VALUE'} = join ', ', @{ $args{'VALUE'} };
 +                }
 +                $args{'VALUE'} = "($args{VALUE})";
 +                $args{'QUOTEVALUE'} = 0;
 +            }
 +            else {
 +                # otherwise behave in backwards compatible way
 +            }
 +        }
          $args{'OPERATOR'} =~ s/(?:MATCHES|ENDSWITH|STARTSWITH)/LIKE/i;
  
+         if ( $args{'OPERATOR'} =~ /IS/i ) {
+             $args{'VALUE'} = 'NULL';
+             $args{'QUOTEVALUE'} = 0;
+         }
+     }
+ 
+     if ( $args{'QUOTEVALUE'} ) {
          #if we're explicitly told not to to quote the value or
          # we're doing an IS or IS NOT (null), don't quote the operator.
  
@@@ -1557,37 -1506,12 +1546,20 @@@ Alias of a table the field is in; defau
  
  =item FUNCTION
  
- A SQL function that should be selected as the result.  If a FIELD is
- provided, then it is inserted into the function according to the
- following rules:
- 
- =over 4
- 
- =item *
- 
- If the text of the function contains a '?' (question mark), then it is
- replaced with qualified FIELD.
- 
- =item *
- 
- If the text of the function has no '(' (opening parenthesis), then the
- qualified FIELD is appended in parentheses to the text.
- 
- =item *
- 
- Otherwise, the function is inserted verbatim, with no substitution.
- 
- =back
+ A SQL function that should be selected instead of FIELD or applied to it.
  
 +=item AS
 +
 +The B<column> alias to use instead of the default.  The default column alias is
 +either the column's name (i.e. what is passed to FIELD) if it is in this table
 +(ALIAS is 'main') or an autogenerated alias.  Pass C<undef> to skip column
 +aliasing entirely.
 +
  =back
  
 -Above arguments combined according to L</CombineFunctionWithField>.
++C<FIELD>, C<ALIAS> and C<FUNCTION> are combined according to
++L</CombineFunctionWithField>.
+ 
  If a FIELD is provided and it is in this table (ALIAS is 'main'), then
  the column named FIELD and can be accessed as usual by accessors:
  
@@@ -1621,57 -1542,27 +1593,30 @@@ sub Column 
  
      $args{'ALIAS'} ||= 'main';
  
-     my $name;
-     if ( $args{FIELD} && $args{FUNCTION} ) {
-         $name = $args{'ALIAS'} .'.'. $args{'FIELD'};
- 
-         my $func = $args{FUNCTION};
-         if ( $func =~ /^DISTINCT\s*COUNT$/i ) {
-             $name = "COUNT(DISTINCT $name)";
-         }
-         # If we want to substitute 
-         elsif ($func =~ s/\?/$name/g) {
-             $name = $func;
-         }
-         # If we want to call a simple function on the column
-         elsif ($func !~ /\(/)  {
-             $name = "\U$func\E($name)";
-         } else {
-             $name = $func;
-         }
-     }
-     elsif ( $args{FUNCTION} ) {
-         $name = $args{FUNCTION};
-     }
-     elsif ( $args{FIELD} ) {
-         $name = $args{'ALIAS'} .'.'. $args{'FIELD'};
-     }
-     else {
-         $name = 'NULL';
-     }
+     my $name = $self->CombineFunctionWithField( %args ) || 'NULL';
  
 -    my $column;
 -    if (
 -        $args{FIELD} && $args{ALIAS} eq 'main'
 -        && (!$args{'TABLE'} || $args{'TABLE'} eq $self->Table )
 -    ) {
 -        $column = $args{FIELD};
 -
 -        # make sure we don't fetch columns with duplicate aliases
 -        if ( $self->{columns} ) {
 -            my $suffix = " AS \L$column";
 -            if ( grep index($_, $suffix, -length $suffix) >= 0, @{ $self->{columns} } ) {
 -                $column .= scalar @{ $self->{columns} };
 +    my $column = $args{'AS'};
 +
 +    if (not defined $column and not exists $args{'AS'}) {
 +        if (
 +            $args{FIELD} && $args{ALIAS} eq 'main'
 +            && (!$args{'TABLE'} || $args{'TABLE'} eq $self->Table )
 +        ) {
 +            $column = $args{FIELD};
 +
 +            # make sure we don't fetch columns with duplicate aliases
 +            if ( $self->{columns} ) {
 +                my $suffix = " AS \L$column";
 +                if ( grep index($_, $suffix, -length $suffix) >= 0, @{ $self->{columns} } ) {
 +                    $column .= scalar @{ $self->{columns} };
 +                }
              }
          }
 +        else {
 +            $column = "col" . @{ $self->{columns} ||= [] };
 +        }
      }
 -    else {
 -        $column = "col" . @{ $self->{columns} ||= [] };
 -    }
 -    push @{ $self->{columns} ||= [] }, "$name AS \L$column";
 +    push @{ $self->{columns} ||= [] }, defined($column) ? "$name AS \L$column" : $name;
      return $column;
  }
  
diff --cc t/01searches.t
index 5d16196,664fcb7..b875240
--- a/t/01searches.t
+++ b/t/01searches.t
@@@ -7,7 -7,7 +7,7 @@@ use Test::More
  BEGIN { require "t/utils.pl" }
  our (@AvailableDrivers);
  
- use constant TESTS_PER_DRIVER => 144;
 -use constant TESTS_PER_DRIVER => 122;
++use constant TESTS_PER_DRIVER => 149;
  
  my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
  plan tests => $total;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list