My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
CodeComparison1  
Code Comparison 1
Updated Nov 18, 2010 by dan...@drjays.com

Code Comparison 1

Consider a DB call that might look like this:

        return $self->_error('_enum failed') unless
 	  my $Estatus = $self->_enum('alloc','status');

        my $allocs = $dbh->select(
                                  -table => 'allocation',
                                  -fields => 'alloc_id product_id date status quantity',
                                  -where => {
                                             product_id => ['d in',@{$prodids}],
                                             status     => ['d in', $Estatus->_multi('active inactive')],
                                            },
                                 );

       foreach my $alloc (@{$allocs}){

              if($alloc->{status} == $Estatus->active))

                  $dbh->update(
                               -table => 'allocation',
                               -fields => {
                                           quantity   => ['d', $alloc->{quantity} + 1],
                                          },
                               -where => {
                                          alloc_id => ['d',$alloc->{alloc_id}],
                                         },
                              );

              }

       }

Could potentially be made to look like this:

      my $allocs = $dbh->allocation->where( product_id => $prodids, status => 'active inactive' );

      while (my $alloc = $allocs->next){

          if($alloc->status eq 'active'){
              $alloc->quantity( $alloc->quantity + 1 );
          }

      }

Obviously it's a whole lot shorter, and why are there no fields specified on the record retrieval?.

Powered by Google Project Hosting