i was trying to do '!Fields' => 'function(foo, bar) AS baz', which
confused DBIx::Recordset->BuildFields, since it does (basically) a
split on /,/.

So i patched it to take !Fields as an array ref, in which case it assumes
you have already separated the fields appropriately.

only seen light testing, but seems ok so far.


this patch also fixes a bug with duplicate Link destinations, where it
would take the NameFields from one Link and the table join criteria
from another (now it takes them both from the first Link encountered).

fixed a "$Fields" typo in the documentation, which (iirc) has already
caught someone out.

adjusted some logic when building LinkName=2 versions of fields. now
skips if NameFields is [] (which can happen with duplicate Link
destinations).

also added a hefty debug output block to BuildFields (if Debug > 3).
i found it invaluable while working through these things, feel free
to remove it if you don't like it.


its all still in the one patch, but should be immediately obvious what
fixes what. i apologise if it isn't.

-- 
 - Gus
--- Recordset.pm.orig   Tue Feb 12 14:47:38 2002
+++ /usr/share/perl5/DBIx/Recordset.pm  Tue Feb 19 12:45:20 2002
@@ -1410,8 +1410,9 @@
         else
             {
             my $tab4f  = $self -> {'*Table4Field'} ;
-            #my @allfields = map { (/\./)?$_:"$tab4f->{$_}.$_" } split (/\s*,\s*/, 
$fields) ;
-            my @allfields = map { (/\./)?$_:"$tab4f->{$_}.$_" } quotewords 
('\s*,\s*', 0, $fields) ;
+
+           my $splitfields = ref($fields)?$fields:[quotewords ('\s*,\s*',0,$fields)] ;
+            my @allfields = map { (/\./)?$_:"$tab4f->{$_}.$_" } @$splitfields ;
             shift @allfields if (lc($allfields[0]) eq 'distinct') ;
             $self->{'*SelectFields'} = \@allfields ;
             }
@@ -1800,8 +1801,8 @@
     #print LOG "###--> numtabs = $numtabs\n" ;
     if (defined ($fields) && !($fields =~ /^\s*\*\s*$/))
         {
-        #@allfields = map { (/\./)?$_:"$tab4f->{$_}.$_" } split (/\s*,\s*/, $fields) ;
-        @allfields = map { (/\./ || !$tab4f->{$_})?$_:"$tab4f->{$_}.$_" } quotewords 
('\s*,\s*', 0, $fields) ;
+       my $splitfields = ref($fields)?$fields:[quotewords ('\s*,\s*', 0, $fields)] ;
+        @allfields = map { (/\./ || !$tab4f->{$_})?$_:"$tab4f->{$_}.$_" } 
+@$splitfields ;
         #print LOG "###allfields = @allfields\n" ;
        }
     else
@@ -1883,13 +1884,38 @@
                     }
                 }
 
-            $numtabs-- if (!exists $tables{$link->{'!Table'}}) ;
+           if (!exists $tables{$link->{'!Table'}})
+               {
+               $numtabs-- ;
            $tables{$link->{'!Table'}} = "$fn = 
$link->{'!Table'}.$link->{'!LinkedField'}" ;
             }
+            }
         elsif ($debug > 2 && !$link -> {'!LinkedBy'})
             { print LOG "[$$] DB:  No name, so do not add to $self->{'*Table'} linked 
name field $link->{'!Table'}.$fn\n" ;}            
         }
 
+    if ($debug > 3) {
+      print LOG "[$$] DB: allfields:\n";
+      for (my $i = 0; $i < @allfields; $i++) {
+       print LOG "[$$] DB:     $i $allfields[$i]\n";
+      }
+      print LOG "[$$] DB: orderedfields:\n";
+      for (my $i = 0; $i < @orderedfields; $i++) {
+       print LOG "[$$] DB:     $i $orderedfields[$i]\n";
+      }
+      print LOG "[$$] DB: fields:\n";
+      print LOG "[$$] DB:      $_ => $fields{$_}\n" foreach sort keys %fields;
+      print LOG "[$$] DB: replace:\n";
+      for (my $i = 0; $i < @orderedfields; $i++) {
+       my @repl = ();
+       push @repl, $orderedfields[$_] foreach @{$replace[$i]};
+       my $repl = join ',', @repl;
+       print LOG "[$$] DB:      $orderedfields[$i] -> $repl\n";
+      }
+      print LOG "[$$] DB: tables:\n";
+      print LOG "[$$] DB:      $_ => $tables{$_}\n" foreach sort keys %tables;
+    }
+
     #my $rfields = join (',', @allfields) ;
     my $rfields = join (',', @orderedfields) ;
     my $rtables = join (',', keys %tables) ;
@@ -3721,7 +3747,7 @@
                 $n = $DBIx::Recordset::PreserveCase?$names -> [$i]:lc ($names -> 
[$i]) ;
                 $of = $ofunc -> [$i] ;
                $data -> {$n} = ($of?(&{$of}($dat->[$i])):$dat->[$i]) ;
-                $data -> {uc($n)} = join (' ', map ({ 
($ofunc->[$_]?(&{$ofunc->[$_]}($dat->[$_])):$dat->[$_])} @$r)) if ($#$r > 0 || $r -> 
[0] != $i) ;
+                $data -> {uc($n)} = join (' ', map ({ 
+($ofunc->[$_]?(&{$ofunc->[$_]}($dat->[$_])):$dat->[$_])} @$r)) unless ($#$r < 0 || $r 
+-> [0] == $i) ;
                 $i++ ;
                 }
             }
@@ -4176,7 +4202,7 @@
 
 
 NOTE 1: Fieldnames specified with !Fields can't be overridden. If you plan
-to use other fields with this object later, use $Fields instead.
+to use other fields with this object later, use $fields instead.
 
 NOTE 2: The keys for the returned hash normally don't have a table part.
 Only the fieldname part forms the key. (See !LongNames for an exception.)
@@ -4747,7 +4773,8 @@
 
 Fields which should be returned by a query. If you have specified multiple
 tables the fieldnames should be unique. If the names are not unique you must
-specify them along with the tablename (e.g. tab1.field).
+specify them along with the tablename (e.g. tab1.field). Multiple fields may
+be given as an array ref or comma-separated.
 
 
 NOTE 1: If B<!fields> is supplied at setup time, this can not be overridden

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to