cvsuser 04/02/03 06:58:42
Modified: App-Repository/lib/App/Repository DBI.pm
Log:
reworked debug_sql
Revision Changes Path
1.16 +79 -38 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.15
retrieving revision 1.16
diff -u -w -r1.15 -r1.16
--- DBI.pm 2 Feb 2004 20:58:52 -0000 1.15
+++ DBI.pm 3 Feb 2004 14:58:41 -0000 1.16
@@ -1,13 +1,13 @@
######################################################################
-## File: $Id: DBI.pm,v 1.15 2004/02/02 20:58:52 spadkins Exp $
+## File: $Id: DBI.pm,v 1.16 2004/02/03 14:58:41 spadkins Exp $
######################################################################
use App;
use App::Repository;
package App::Repository::DBI;
-$VERSION = do { my @r=(q$Revision: 1.15 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
+$VERSION = do { my @r=(q$Revision: 1.16 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
@ISA = ( "App::Repository" );
@@ -341,16 +341,20 @@
$dbh = $self->{dbh};
return undef if (!$dbh);
+ my $debug_sql = $self->{context}{options}{debug_sql};
+ if ($debug_sql) {
+ print "DEBUG_SQL: _get_row()\n";
+ print $sql;
+ }
$row = $dbh->selectrow_arrayref($sql);
- if ($self->{context}{options}{debug_sql}) {
- my $level = $self->{context}{options}{debug_sql};
- print "DEBUG_SQL: in _get_row(), after call to _selectrange_arrayref()\n";
- print "DEBUG_SQL:\n$sql\n";
- if ($level >= 2) {
- print "DEBUG_SQL: [", ($row ? join("|",@$row) : ""), "]\n";
+ if ($debug_sql) {
+ print "DEBUG_SQL: nrows [", (defined $row ? 1 : 0), "] $DBI::errstr\n";
+ if ($debug_sql >= 2) {
+ print "DEBUG_SQL: [", ($row ? join("|",map { defined $_ ? $_ : "undef"
} @$row) : ""), "]\n";
}
print "\n";
}
+
&App::sub_exit($row) if ($App::trace_subs);
return($row);
}
@@ -374,18 +378,23 @@
$options = {} if (!$options);
$startrow = $options->{startrow} || 0;
$endrow = $options->{endrow} || 0;
+
+ my $debug_sql = $self->{context}{options}{debug_sql};
+ if ($debug_sql) {
+ print "DEBUG_SQL: _get_rows()\n";
+ print $sql;
+ }
$rows = $self->_selectrange_arrayref($sql, $startrow, $endrow);
- if ($self->{context}{options}{debug_sql}) {
- my $level = $self->{context}{options}{debug_sql};
- print "DEBUG_SQL: in _get_rows(), after call to _selectrange_arrayref()\n";
- print "DEBUG_SQL:\n$sql\n";
- if ($level >= 2) {
+ if ($debug_sql) {
+ print "DEBUG_SQL: nrows [", (defined $rows ? ($#$rows+1) : 0), "]
$DBI::errstr\n";
+ if ($debug_sql >= 2) {
foreach my $row (@$rows) {
- print "DEBUG_SQL: [", join("|",@$row), "]\n";
+ print "DEBUG_SQL: [", join("|",map { defined $_ ? $_ : "undef"}
@$row), "]\n";
}
}
print "\n";
}
+
&App::sub_exit($rows) if ($App::trace_subs);
return($rows);
}
@@ -1701,13 +1710,19 @@
$self->{sql} = $sql;
my $dbh = $self->{dbh};
my $retval = 0;
+
+ my $debug_sql = $self->{context}{options}{debug_sql};
+ if ($debug_sql) {
+ print "DEBUG_SQL: _insert_row()\n";
+ print "DEBUG_SQL: bind vars [", join("|",map { defined $_ ? $_ : "undef" }
@$row), "]\n";
+ print $sql;
+ }
$retval = $dbh->do($sql, undef, @$row) if (defined $dbh);
- if ($self->{context}{options}{debug_sql}) {
- print "DEBUG_SQL: in _insert_row(), after call to do()\n";
- print "DEBUG_SQL:[$retval] [$DBI::errstr]\n";
- print "DEBUG_SQL:\n$sql\n";
+ if ($debug_sql && $debug_sql >= 2) {
+ print "DEBUG_SQL: retval [$retval] $DBI::errstr\n";
print "\n";
}
+
&App::sub_exit($retval) if ($App::trace_subs);
$retval;
}
@@ -1724,15 +1739,21 @@
$ok = 1;
$sql = $self->_mk_insert_row_sql($table, $cols);
+ my $debug_sql = $self->{context}{options}{debug_sql};
foreach $row (@$rows) {
$nrows += $self->{numrows};
+
+ if ($debug_sql) {
+ print "DEBUG_SQL: _insert_rows()\n";
+ print "DEBUG_SQL: bind vars [", join("|",map { defined $_ ? $_ :
"undef" } @$row), "]\n";
+ print $sql;
+ }
$retval = $dbh->do($sql, undef, @$row);
- if ($self->{context}{options}{debug_sql}) {
- print "DEBUG_SQL: in _insert_rows(), after call to do()\n";
- print "DEBUG_SQL:[$retval] [$DBI::errstr]\n";
- print "DEBUG_SQL:\n$sql\n";
+ if ($debug_sql) {
+ print "DEBUG_SQL: retval [$retval] $DBI::errstr\n";
print "\n";
}
+
if (!$retval) {
$self->{numrows} = $nrows;
$ok = 0;
@@ -1751,13 +1772,18 @@
$self->{error} = "";
my $sql = $self->_mk_delete_sql($table, $params, $cols, $row, $options);
$self->{sql} = $sql;
+
+ my $debug_sql = $self->{context}{options}{debug_sql};
+ if ($debug_sql) {
+ print "DEBUG_SQL: _delete()\n";
+ print $sql;
+ }
my $retval = $self->{dbh}->do($sql);
- if ($self->{context}{options}{debug_sql}) {
- print "DEBUG_SQL: in _delete(), after call to do()\n";
- print "DEBUG_SQL:[$retval] [$DBI::errstr]\n";
- print "DEBUG_SQL:\n$sql\n";
+ if ($debug_sql) {
+ print "DEBUG_SQL: retval [$retval] $DBI::errstr\n";
print "\n";
}
+
&App::sub_exit($retval) if ($App::trace_subs);
return($retval);
}
@@ -1773,13 +1799,18 @@
$self->{error} = "";
my $sql = $self->_mk_update_sql($table, $params, $cols, $row, $options);
$self->{sql} = $sql;
+
+ my $debug_sql = $self->{context}{options}{debug_sql};
+ if ($debug_sql) {
+ print "DEBUG_SQL: _update()\n";
+ print $sql;
+ }
my $retval = $self->{dbh}->do($sql);
- if ($self->{context}{options}{debug_sql}) {
- print "DEBUG_SQL: in _update(), after call to do()\n";
- print "DEBUG_SQL:[$retval] [$DBI::errstr]\n";
- print "DEBUG_SQL:\n$sql\n";
+ if ($debug_sql) {
+ print "DEBUG_SQL: retval [$retval] $DBI::errstr\n";
print "\n";
}
+
&App::sub_exit($retval) if ($App::trace_subs);
return($retval);
}
@@ -1793,13 +1824,18 @@
$self->{sql} = $sql;
my $dbh = $self->{dbh};
my $retval = 0;
+
+ my $debug_sql = $self->{context}{options}{debug_sql};
+ if ($debug_sql) {
+ print "DEBUG_SQL: _delete_row()\n";
+ print $sql;
+ }
$retval = $dbh->do($sql) if (defined $dbh);
- if ($self->{context}{options}{debug_sql}) {
- print "DEBUG_SQL: in _delete_row(), after call to do()\n";
- print "DEBUG_SQL:[$retval] [$DBI::errstr]\n";
- print "DEBUG_SQL:\n$sql\n";
+ if ($debug_sql) {
+ print "DEBUG_SQL: retval [$retval] $DBI::errstr\n";
print "\n";
}
+
&App::sub_exit($retval) if ($App::trace_subs);
$retval;
}
@@ -1813,13 +1849,18 @@
$self->{sql} = $sql;
my $dbh = $self->{dbh};
my $retval = 0;
+
+ my $debug_sql = $self->{context}{options}{debug_sql};
+ if ($debug_sql) {
+ print "DEBUG_SQL: _delete_rows()\n";
+ print $sql;
+ }
$retval = $dbh->do($sql) if (defined $dbh);
- if ($self->{context}{options}{debug_sql}) {
- print "DEBUG_SQL: in _delete_rows(), after call to do()\n";
- print "DEBUG_SQL:[$retval] [$DBI::errstr]\n";
- print "DEBUG_SQL:\n$sql\n";
+ if ($debug_sql) {
+ print "DEBUG_SQL: retval [$retval] $DBI::errstr\n";
print "\n";
}
+
&App::sub_exit($retval) if ($App::trace_subs);
$retval;
}