cvs commit: p5ee/App-Repository/t DBI-getset.t

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     04/12/01 12:19:49

  Modified:    App-Repository/lib/App Repository.pm
               App-Repository/lib/App/Repository DBI.pm
               App-Repository/t DBI-getset.t
  Log:
  _set_row() only inserts if options->{create} set, update() can take a hashref for
  
  Revision  Changes    Path
  1.17      +3 -2      p5ee/App-Repository/lib/App/Repository.pm
  
  Index: Repository.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository.pm,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Repository.pm	29 Nov 2004 16:18:55 -0000	1.16
  +++ Repository.pm	1 Dec 2004 20:19:49 -0000	1.17
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Repository.pm,v 1.16 2004/11/29 16:18:55 spadkins Exp $
  +## $Id: Repository.pm,v 1.17 2004/12/01 20:19:49 spadkins Exp $
   #############################################################################
   
   package App::Repository;
  @@ -1337,10 +1337,11 @@
   sub _set_row {
       &App::sub_entry if ($App::trace);
       my ($self, $table, $params, $cols, $row, $options) = @_;
  +    $options = {} if (!$options);
   
       $params = $self->_params_to_hashref($table, $params) if ($params && ref($params) ne "HASH");
       my $nrows = $self->_update($table, $params, $cols, $row, $options);
  -    if ($nrows == 0) {
  +    if ($nrows == 0 && $options->{create}) {
           $nrows = $self->_insert_row($table, $cols, $row, $options);
       }
   
  
  
  
  1.20      +16 -9     p5ee/App-Repository/lib/App/Repository/DBI.pm
  
  Index: DBI.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/DBI.pm,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DBI.pm	19 Nov 2004 04:36:11 -0000	1.19
  +++ DBI.pm	1 Dec 2004 20:19:49 -0000	1.20
  @@ -1,13 +1,13 @@
   
   ######################################################################
  -## File: $Id: DBI.pm,v 1.19 2004/11/19 04:36:11 spadkins Exp $
  +## File: $Id: DBI.pm,v 1.20 2004/12/01 20:19:49 spadkins Exp $
   ######################################################################
   
   use App;
   use App::Repository;
   
   package App::Repository::DBI;
  -$VERSION = do { my @r=(q$Revision: 1.19 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.20 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   @ISA = ( "App::Repository" );
   
  @@ -1483,15 +1483,22 @@
       }
   
       # Now determine what to "set"
  -    for ($colidx = 0; $colidx <= $#$cols; $colidx++) {
  -        next if ($noupdate[$colidx]);
  -        $col = $cols->[$colidx];
  -        next if ($noupdate{$col});
  -        if (!defined $row || $#$row == -1) {
  +    my $ref_row = ref($row);
  +    if (!$ref_row) {
  +        for ($colidx = 0; $colidx <= $#$cols; $colidx++) {
  +            next if ($noupdate[$colidx]);
  +            $col = $cols->[$colidx];
  +            next if ($noupdate{$col});
               push(@set, "$col = ?");
           }
  -        else {
  -            $value = $row->[$colidx];
  +    }
  +    else {
  +        my $is_array = ($ref_row eq "ARRAY");
  +        for ($colidx = 0; $colidx <= $#$cols; $colidx++) {
  +            next if ($noupdate[$colidx]);
  +            $col = $cols->[$colidx];
  +            next if ($noupdate{$col});
  +            $value = $is_array ? $row->[$colidx] : $row->{$col};
               if (!defined $value) {
                   push(@set, "$col = NULL");
               }
  
  
  
  1.5       +2 -1      p5ee/App-Repository/t/DBI-getset.t
  
  Index: DBI-getset.t
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/t/DBI-getset.t,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DBI-getset.t	22 Nov 2004 19:57:03 -0000	1.4
  +++ DBI-getset.t	1 Dec 2004 20:19:49 -0000	1.5
  @@ -134,7 +134,8 @@
   is($hash->{state},      "GA",      "get_hash(1) state");
   
   ok($rep->set("test_person", {first_name => "steve"}, {person_id => 1, age => 41}), "set(table,\$params,\%hash)");
  -ok($rep->set("test_person", {person_id => 8, age => 37, first_name => "nick", gender => "M", state => "NY"}),
  +ok($rep->set("test_person", {person_id => 8, age => 37, first_name => "nick", gender => "M", state => "NY"},
  +    undef, undef, {create=>1}),
       "set(table,\$params,\%hash) : insert");
   is($rep->set("test_person", {gender => "F", age => 41}), 0,
       "set(table,\$params,\%hash) : fails if key not supplied");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.