cvs commit: p5ee/App-Repository/lib/App Repository.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/04/25 09:18:31

  Modified:    App-Repository/lib/App Repository.pm
  Log:
  fix set_rows to work (with create option)
  
  Revision  Changes    Path
  1.20      +9 -5      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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Repository.pm	31 Jan 2005 20:50:16 -0000	1.19
  +++ Repository.pm	25 Apr 2005 16:18:31 -0000	1.20
  @@ -16,7 +16,7 @@
   
   =head1 NAME
   
  -App::Repository - Interface for data persistence
  +App::Repository - a logical data access layer (works with App::Context), enabling an application to store and retrieve object data, relational data, and scalar data to any data repository such as databases, file systems, remote web sites, etc.
   
   =head1 SYNOPSIS
   
  @@ -1382,12 +1382,12 @@
   sub _set_rows {
       &App::sub_entry if ($App::trace);
       my ($self, $table, $params, $cols, $rows, $options) = @_;
  -    $params = $self->_params_to_hashref($table, $params) if (ref($params) ne "HASH");
  +    $params = $self->_params_to_hashref($table, $params) if ($params && ref($params) ne "HASH");
   
       my $tabledef = $self->{table}{$table};
   
       my ($primary_key, @keycolidx, $keypos, %keypos, $keys_supplied);
  -    my ($row, $colidx, $nrows);
  +    my ($row, $colidx, $nrows, $success);
       $nrows = 0;
       if (! defined $params) {
           $primary_key = $tabledef->{primary_key};
  @@ -1405,7 +1405,11 @@
           }
           die "Tried to set_rows() and the primary key is not among the columns" if ($keys_supplied != $#$primary_key+1);
           foreach $row (@$rows) {
  -            $nrows += $self->_update($table, $cols, $row, \@keycolidx);
  +            $success = $self->_update($table, \@keycolidx, $cols, $row, $options);
  +            if ($success == 0 && $options->{create}) {
  +                $success = $self->_insert_row($table, $cols, $row, $options);
  +            }
  +            $nrows += $success;
           }
       }
       elsif (ref($params) eq "ARRAY") {
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.