cvsuser     02/06/07 10:55:07

  Modified:    P5EEx/Blue/P5EEx/Blue/Repository DBI.pm
  Log:
  support outer joins
  
  Revision  Changes    Path
  1.12      +23 -14    p5ee/P5EEx/Blue/P5EEx/Blue/Repository/DBI.pm
  
  Index: DBI.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Repository/DBI.pm,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -w -r1.11 -r1.12
  --- DBI.pm    17 Apr 2002 19:19:54 -0000      1.11
  +++ DBI.pm    7 Jun 2002 17:55:07 -0000       1.12
  @@ -1,13 +1,13 @@
   
   ######################################################################
  -## File: $Id: DBI.pm,v 1.11 2002/04/17 19:19:54 spadkins Exp $
  +## File: $Id: DBI.pm,v 1.12 2002/06/07 17:55:07 spadkins Exp $
   ######################################################################
   
   use P5EEx::Blue::P5EE;
   use P5EEx::Blue::Repository;
   
   package P5EEx::Blue::Repository::DBI;
  -$VERSION = do { my @r=(q$Revision: 1.11 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.12 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   @ISA = ( "P5EEx::Blue::Repository" );
   
  @@ -824,30 +824,31 @@
       # and build the join criteria
       ############################################################
   
  -    my ($dbtable, $tablealias, @from_tables);
  +    my ($dbtable, $tablealias, @from_tables, $tableref);
  +    my (@outer_join_clauses);
   
       foreach $tablealias (@$tablealiases) {
  +        #print "checking table $tablealias\n";
           if ($reqd_tables{$tablealias}) {
               $dbtable = $tablealiashref->{$tablealias}{table};
  -            if ($dbtable) {
  -                push(@from_tables,"$dbtable $tablealias");
  +            $tableref = ($dbtable) ? "$dbtable $tablealias" : $tablealias;
  +            $where_condition = $tablealiashref->{$tablealias}{joincriteria};
  +            if ($tablealiashref->{$tablealias}{cardinality_zero}) {
  +                push(@outer_join_clauses, "left join $tableref on 
$where_condition") if ($where_condition);
  +                #print "   $tablealias is [$dbtable] as [$tableref] where 
[$where_condition] (outer)\n";
               }
               else {
  -                push(@from_tables,$tablealias);
  -            }
  -            $where_condition = $tablealiashref->{$tablealias}{joincriteria};
               push(@join_conditions, split(/ +and +/,$where_condition)) if 
($where_condition);
  +                push(@from_tables, $tableref);
  +                #print "   $tablealias is [$dbtable] as [$tableref] where 
[$where_condition]\n";
  +            }
           }
       }
       if ($#from_tables == -1 && $#$tablealiases > -1) {
           $tablealias = $tablealiases->[0];
           $table = $tablealiashref->{$tablealias}{table};
  -        if ($table) {
  -            push(@from_tables,"$table $tablealias");
  -        }
  -        else {
  -            push(@from_tables,$tablealias);
  -        }
  +        $tableref = ($table) ? "$table $tablealias" : $tablealias;
  +        push(@from_tables, $tableref);
       }
   
       ############################################################
  @@ -862,6 +863,11 @@
                    "from\n   " .
                           join(",\n   ",@from_tables) . "\n";
       }
  +
  +    if ($#outer_join_clauses >= 0) {
  +        $sql .= join("\n",@outer_join_clauses) . "\n";
  +    }
  +
       if ($#join_conditions >= 0) {
           $sql .= "where " . join("\n  and ",@join_conditions) . "\n";
       }
  @@ -901,6 +907,7 @@
   
   sub require_tables {
      my ($self, $dbexpr, $reqd_tables, $tablealiashref, $require_type) = @_;
  +   #print "require_tables($dbexpr,...,...,$require_type)\n";
      my ($tablealias, $tablealias2, @tablealias, %tableseen, $dependencies);
      while ($dbexpr =~ s/([a-zA-Z_][a-zA-Z_0-9]*)\.[a-zA-Z_][a-zA-Z_0-9]*//) {
         if (defined $tablealiashref->{$1} && !$tableseen{$1}) {
  @@ -910,12 +917,14 @@
         while ($tablealias = pop(@tablealias)) {
            if (! defined $reqd_tables->{$tablealias}) {
               $reqd_tables->{$tablealias} = $require_type;
  +            #print "table required: $tablealias => $require_type\n";
               $dependencies = $tablealiashref->{$tablealias}{dependencies};
               push(@tablealias, @$dependencies)
                  if (defined $dependencies && ref($dependencies) eq "ARRAY");
            }
            elsif ($reqd_tables->{$tablealias} < $require_type) {
               $reqd_tables->{$tablealias} = $require_type;
  +            #print "table required: $tablealias => $require_type\n";
            }
         }
      }
  
  
  


Reply via email to