App-Repository

 view release on metacpan or  search on metacpan

lib/App/Repository.pm  view on Meta::CPAN

            $columns = [ keys %$hash ] if (!$columns);
        }
        elsif (ref($rows) eq "ARRAY" && ref($rows->[0]) eq "HASH") {
            $hashes = $rows;
            $hash = $hashes->[0];
            if (ref($cols) eq "ARRAY") {
                $columns = $cols;
            }
            else {
                my $table_def = $self->{table}{$table};
                $columns = $table_def->{columns};
                $columns = [ keys %$hash ] if (!$columns || $#$columns == -1);
            }
        }
        if ($hashes) {
            my (@cols, @rows, $col, $row);
            foreach $col (@$columns) {
                if (exists $hash->{$col}) {
                    push(@cols, $col);
                }
            }
            foreach $hash (@$hashes) {
                $row = [];
                foreach $col (@cols) {
                    push(@$row, $hash->{$col});
                }
                push(@rows, $row);
            }
            $nrows = $self->_insert_rows($table, \@cols, \@rows, $options);
        }
        else {
            $nrows = $self->_insert_rows($table, $cols, $rows, $options);
        }
    }
    &App::sub_exit($nrows) if ($App::trace);
    $nrows;
}

sub delete {
    &App::sub_entry if ($App::trace);
    my ($self, $table, $params, $cols, $row, $options) = @_;
    die "delete(): params undefined" if (!defined $params);
    my $repname = $self->{table}{$table}{repository};
    my $realtable = $self->{table}{$table}{table} || $table;
    my ($retval);
    if (defined $repname && $repname ne $self->{name}) {
        my $rep = $self->{context}->repository($repname);
        $retval = $rep->delete($realtable, $cols, $row, $options);
    }
    elsif (defined $realtable && $realtable ne $table) {
        $retval = $self->delete($realtable, $cols, $row, $options);
    }
    else {
        $self->_load_table_metadata($table) if (! defined $self->{table}{$table}{loaded});
        $retval = $self->_delete($table,$params,$cols,$row,$options);
    }
    &App::sub_exit($retval) if ($App::trace);
    return($retval);
}

sub update {
    &App::sub_entry if ($App::trace);
    my ($self, $table, $params, $cols, $row, $options) = @_;
    die "update(): params undefined" if (!defined $params);
    my $repname = $self->{table}{$table}{repository};
    my $realtable = $self->{table}{$table}{table} || $table;
    my ($retval);
    if (defined $repname && $repname ne $self->{name}) {
        my $rep = $self->{context}->repository($repname);
        $retval = $rep->update($realtable, $cols, $row, $options);
    }
    elsif (defined $realtable && $realtable ne $table) {
        $retval = $self->update($realtable, $cols, $row, $options);
    }
    else {
        $self->_load_table_metadata($table) if (! defined $self->{table}{$table}{loaded});
        $retval = $self->_update($table,$params,$cols,$row,$options);
    }
    &App::sub_exit($retval) if ($App::trace);
    return($retval);
}

sub _insert_row {
    &App::sub_entry if ($App::trace);
    my ($self, $table, $cols, $row, $options) = @_;
    $self->{error} = "";
    my $retval = 0;
    die "_insert_row(): not yet implemented";
    &App::sub_exit($retval) if ($App::trace);
    return($retval);
}

sub _insert_rows {
    &App::sub_entry if ($App::trace);
    my ($self, $table, $cols, $rows, $options) = @_;
    $self->{error} = "";
    my $retval = 0;
    die "_insert_rows(): not yet implemented";
    &App::sub_exit($retval) if ($App::trace);
    return($retval);
}

sub _delete {
    &App::sub_entry if ($App::trace);
    my ($self, $table, $params, $cols, $row, $options) = @_;

    $self->{error} = "";
    my $retval = 0;
    die "_delete(): not yet implemented";

    &App::sub_exit($retval) if ($App::trace);
    return($retval);
}

# $nrows = $rep->_update($table, \%params,    \@cols, \@row, \%options);
# $nrows = $rep->_update($table, \@keycolidx, \@cols, \@row, \%options);
# $nrows = $rep->_update($table, \@paramcols, \@cols, \@row, \%options);
# $nrows = $rep->_update($table, $key,        \@cols, \@row, \%options);
# $nrows = $rep->_update($table, undef,       \@cols, \@row, \%options);
sub _update {
    &App::sub_entry if ($App::trace);



( run in 0.599 second using v1.01-cache-2.11-cpan-df04353d9ac )