cvsuser 03/08/05 10:49:36
Modified: P5EEx/Blue/P5EEx/Blue/Repository DBI.pm
Log:
took out locking from store_rows()
Revision Changes Path
1.27 +120 -84 p5ee/P5EEx/Blue/P5EEx/Blue/Repository/DBI.pm
Index: DBI.pm
===================================================================
RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Repository/DBI.pm,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -w -r1.26 -r1.27
--- DBI.pm 19 Jul 2003 03:48:21 -0000 1.26
+++ DBI.pm 5 Aug 2003 17:49:36 -0000 1.27
@@ -1,13 +1,13 @@
######################################################################
-## File: $Id: DBI.pm,v 1.26 2003/07/19 03:48:21 spadkins Exp $
+## File: $Id: DBI.pm,v 1.27 2003/08/05 17:49:36 spadkins Exp $
######################################################################
use P5EEx::Blue::P5EE;
use P5EEx::Blue::Repository;
package P5EEx::Blue::Repository::DBI;
-$VERSION = do { my @r=(q$Revision: 1.26 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
+$VERSION = do { my @r=(q$Revision: 1.27 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
@ISA = ( "P5EEx::Blue::Repository" );
@@ -1641,24 +1641,22 @@
# $nrows = $rep->store_rows ($table, [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL
PROTECTED], $update_first);
sub store_rows {
- my ($self, $table, $cols, $rows, $keycolidx, $update_first, $row_crit) = @_;
+ my ($self, $table, $cols, $rows, $keycolidx, $update_first, $params) = @_;
my ($row, $ok, $nrows, $rownum, $colnum, $column, $tabledef);
- my ($pk_column, @insert_cols, @insert_cols_ih);
+ my ($pk_column, $pk_column_idx, @insert_cols, @insert_cols_ih);
my ($id, %paramvalues, $oldrow, $oldrows, %oldrows, $different, $key);
- my ($table_ih, $auto_id, $current_datetime, $context, $error, $sql);
+ my ($table_ih, $auto_id, $current_datetime, $context, $errmsg, $sql);
my ($column_obsolete_dttm, $column_change_dttm, %colidx, %nodiff_column);
$self->{error} = "";
$context = $self->{context};
if ($P5EEx::Blue::DEBUG && $context->dbg(1)) {
- $context->dbgprint("store_rows($table, col=$cols, rows=$rows (", ($#$rows +
1), "), kidx=$keycolidx, up=$update_first, crit=$row_crit)");
+ $context->dbgprint("store_rows($table, col=$cols, rows=$rows (", ($#$rows +
1), "), kidx=$keycolidx, up=$update_first, crit=$params)");
$context->dbgprint(" cols=[", join("|",@$cols), "]") if ($cols);
$context->dbgprint(" keycolidx=[", join("|",@$keycolidx), "]") if
($keycolidx);
- $context->dbgprint(" rowcrit=[", join("|",%$row_crit),"]") if
($row_crit);
+ $context->dbgprint(" rowcrit=[", join("|",%$params),"]") if ($params);
}
- #$self->store_begin($table);
- $self->_lock_table($table);
eval {
$tabledef = $self->{table}{$table};
$table_ih = $tabledef->{table_ih} || "";
@@ -1681,18 +1679,20 @@
$context->dbgprint(" auto_id=$auto_id pk=$pk_column
chg=$column_change_dttm obs=$column_obsolete_dttm");
}
- if (($auto_id && $pk_column) ||
- ($column_change_dttm && $column_obsolete_dttm)) {
-
for ($colnum = 0; $colnum <= $#$cols; $colnum++) {
$column = $cols->[$colnum];
$colidx{$column} = $colnum;
}
+ $pk_column_idx = $colidx{$pk_column};
- if ($pk_column && ! defined $colidx{$pk_column}) {
+ if (($auto_id && $pk_column) ||
+ ($column_change_dttm && $column_obsolete_dttm)) {
+
+ if ($pk_column && ! defined $pk_column_idx) {
push(@insert_cols, $pk_column);
push(@insert_cols_ih, $pk_column);
$colidx{$pk_column} = $#insert_cols;
+ $pk_column_idx = $#insert_cols;
}
if ($column_change_dttm && ! defined $colidx{$column_change_dttm}) {
@@ -1715,11 +1715,11 @@
}
%oldrows = ();
- if (defined $row_crit) {
+ if (defined $params) {
$oldrows = [];
my ($tmprows, %newrows);
- $tmprows = $self->select_rows($table,[EMAIL PROTECTED],undef,$row_crit);
+ $tmprows = $self->select_rows($table,[EMAIL PROTECTED],undef,$params);
for ($rownum = 0; $rownum <= $#$tmprows; $rownum++) {
$oldrow = $tmprows->[$rownum];
@@ -1746,8 +1746,8 @@
$current_datetime = $self->current_datetime() if (%oldrows &&
!$current_datetime);
if ($P5EEx::Blue::DEBUG && $context->dbg(1)) {
- $error = $self->error();
- $context->dbgprint("store_rows($table): replacing ", $#$tmprows +
1, " $error");
+ $errmsg = $self->error();
+ $context->dbgprint("store_rows($table): replacing ", $#$tmprows +
1, " $errmsg");
}
}
else {
@@ -1812,91 +1812,127 @@
# only if it is considered different do we try to physically store
the row
if ($different) {
# substitute any defaults (todo)
- if ($table_ih) {
+ $ok = $self->update_row($table,$cols,$row,$keycolidx);
+ if ($ok && $table_ih) {
if ($column_obsolete_dttm && $column_change_dttm) {
$oldrow->[$colidx{$column_obsolete_dttm}] =
$row->[$colidx{$column_change_dttm}];
}
+ $ok = 0;
+ $errmsg = "";
+ eval {
$ok = $self->insert_row($table_ih,[EMAIL
PROTECTED],$oldrow);
- $ok = 1 if (!$ok && $self->error() =~ /duplicate/i);
+ $errmsg = $self->error();
+ };
+ $errmsg = $@ if ($@);
+ if (!$ok && $errmsg =~ /duplicate/i) {
+ $ok = 1;
+ print STDERR "store_rows() DUP:
insert_row($table_ih,...)\n";
+ print STDERR " [", join("|", @insert_cols_ih), "]\n";
+ print STDERR " [", join("|", @$oldrow), "]\n";
+ }
+ elsif ($errmsg) {
+ print STDERR "store_rows() ERR:
insert_row($table_ih,...) $errmsg\n";
+ print STDERR " [", join("|", @insert_cols_ih), "]\n";
+ print STDERR " [", join("|", @$oldrow), "]\n";
+ }
}
- $ok = $self->update_row($table,$cols,$row,$keycolidx) if ($ok);
}
if ($P5EEx::Blue::DEBUG && $context->dbg(1)) {
$context->dbgprint("store_rows() old=[", join(",",@$oldrow),
"]");
$context->dbgprint(" new=[", join(",",@$row), "]");
- $error = $self->error();
- $sql = $error ? $self->{sql} : "";
- $context->dbgprint(" diff=$different (at
colidx=$colnum) ok=$ok err=$error $sql");
+ $errmsg = $self->error();
+ $sql = $errmsg ? $self->{sql} : "";
+ $context->dbgprint(" diff=$different (at
colidx=$colnum) ok=$ok err=$errmsg $sql");
}
$nrows++ if ($ok);
}
else {
# next if (does not have permission to insert); (todo)
- if (! $row->[$colidx{$pk_column}]) {
+ if (! $row->[$pk_column_idx]) {
# if we need to automatically allocate an ID ...
if ($auto_id) {
$id = $self->next_id($table, $id);
- $row->[$colidx{$pk_column}] = $id;
+ $row->[$pk_column_idx] = $id;
}
else { # give it 0 and let the DB assign an ID
- $row->[$colidx{$pk_column}] = 0;
+ $row->[$pk_column_idx] = 0;
}
}
+ $ok = 0;
+ $errmsg = "";
+ eval {
$ok = $self->insert_row($table,[EMAIL PROTECTED],$row);
- $error = $self->error();
+ $errmsg = $self->error();
+ };
+ $errmsg = $@ if ($@);
+ if (!$ok && $errmsg =~ /duplicate/i) {
+ $ok = 1;
+ print STDERR "store_rows() DUP: insert_row($table,...)\n";
+ print STDERR " [", join("|", @insert_cols), "]\n";
+ print STDERR " [", join("|", @$row), "]\n";
+ }
+ elsif ($errmsg) {
+ print STDERR "store_rows() ERR: insert_row($table,...)
$errmsg\n";
+ print STDERR " [", join("|", @insert_cols), "]\n";
+ print STDERR " [", join("|", @$row), "]\n";
+ }
if ($P5EEx::Blue::DEBUG && $context->dbg(1)) {
$context->dbgprint("store_rows() new=[", join(",",@$row), "]");
- $sql = $error ? $self->{sql} : "";
- $context->dbgprint(" ok=$ok err=$error $sql");
- }
- if ($ok) {
- $nrows++;
- }
- elsif ($error =~ /duplicate/i) {
- $ok = 1;
+ $sql = $errmsg ? $self->{sql} : "";
+ $context->dbgprint(" ok=$ok err=$errmsg
$sql");
}
+ $nrows++ if ($ok);
}
-
- last if (!$ok);
}
- if (defined $row_crit && %oldrows) {
+ if (defined $params && %oldrows) {
foreach $key (keys %oldrows) {
$oldrow = $oldrows{$key};
- $ok = 1;
- if ($table_ih) {
+ $ok = $self->delete_row($table,$cols,$oldrow,$keycolidx);
+ if ($ok && $table_ih) {
if ($column_obsolete_dttm) {
$current_datetime = $self->current_datetime() if
(!$current_datetime);
$oldrow->[$colidx{$column_obsolete_dttm}] =
$current_datetime;
}
+ $ok = 0;
+ $errmsg = "";
+ eval {
$ok = $self->insert_row($table_ih,[EMAIL PROTECTED],$oldrow);
- $ok = 1 if (!$ok && $self->error() =~ /duplicate/i);
+ $errmsg = $self->error();
+ };
+ $errmsg = $@ if ($@);
+ if (!$ok && $errmsg =~ /duplicate/i) {
+ $ok = 1;
+ print STDERR "store_rows() DUP:
insert_row($table_ih,...)\n";
+ print STDERR " [", join("|", @insert_cols_ih), "]\n";
+ print STDERR " [", join("|", @$oldrow), "]\n";
+ }
+ elsif ($errmsg) {
+ print STDERR "store_rows() ERR: insert_row($table_ih,...)
$errmsg\n";
+ print STDERR " [", join("|", @insert_cols_ih), "]\n";
+ print STDERR " [", join("|", @$oldrow), "]\n";
+ }
}
- $ok = $self->delete_row($table,$cols,$oldrow,$keycolidx) if ($ok);
if ($P5EEx::Blue::DEBUG && $context->dbg(1)) {
$context->dbgprint("store_rows() del=[", join(",",@$oldrow),
"]");
- $error = $self->error();
- $sql = $error ? $self->{sql} : "";
- $context->dbgprint(" ok=$ok err=$error $sql");
+ $errmsg = $self->error();
+ $sql = $errmsg ? $self->{sql} : "";
+ $context->dbgprint(" ok=$ok err=$errmsg
$sql");
}
-
- last if (!$ok);
}
}
};
if ($@) {
- $self->_unlock_table($table);
- die "Exception in store_rows(): $@";
+ $errmsg = $@;
+ die "Exception in store_rows(): $errmsg";
}
- $self->_unlock_table($table);
- #$self->store_end($table);
$self->{numrows} = $nrows;
- $nrows;
+ return($nrows);
}
#sub store_begin {