cvsuser 04/02/02 12:58:52
Modified: App-Repository/lib/App/Repository DBI.pm
Log:
added 'debug_sql' option to all operations
Revision Changes Path
1.15 +55 -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.14
retrieving revision 1.15
diff -u -w -r1.14 -r1.15
--- DBI.pm 18 Nov 2003 21:38:10 -0000 1.14
+++ DBI.pm 2 Feb 2004 20:58:52 -0000 1.15
@@ -1,13 +1,13 @@
######################################################################
-## File: $Id: DBI.pm,v 1.14 2003/11/18 21:38:10 spadkins Exp $
+## File: $Id: DBI.pm,v 1.15 2004/02/02 20:58:52 spadkins Exp $
######################################################################
use App;
use App::Repository;
package App::Repository::DBI;
-$VERSION = do { my @r=(q$Revision: 1.14 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
+$VERSION = do { my @r=(q$Revision: 1.15 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
@ISA = ( "App::Repository" );
@@ -342,6 +342,15 @@
return undef if (!$dbh);
$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";
+ }
+ print "\n";
+ }
&App::sub_exit($row) if ($App::trace_subs);
return($row);
}
@@ -366,13 +375,13 @@
$startrow = $options->{startrow} || 0;
$endrow = $options->{endrow} || 0;
$rows = $self->_selectrange_arrayref($sql, $startrow, $endrow);
- if ($self->{context}{initconf}{debugsql}) {
- my $level = $self->{context}{initconf}{debugsql};
- print "DEBUGSQL: in _get_rows(), from _selectrange_arrayref()\n";
- print "DEBUGSQL:\n$sql\n";
+ 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) {
foreach my $row (@$rows) {
- print "DEBUGSQL: [", join("|",@$row), "]\n";
+ print "DEBUG_SQL: [", join("|",@$row), "]\n";
}
}
print "\n";
@@ -1693,6 +1702,12 @@
my $dbh = $self->{dbh};
my $retval = 0;
$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";
+ print "\n";
+ }
&App::sub_exit($retval) if ($App::trace_subs);
$retval;
}
@@ -1702,7 +1717,7 @@
&App::sub_entry if ($App::trace_subs);
my ($self, $table, $cols, $rows) = @_;
$self->{error} = "";
- my ($row, $sql, $nrows, $ok);
+ my ($row, $sql, $nrows, $ok, $retval);
my $dbh = $self->{dbh};
return 0 if (!defined $dbh);
@@ -1711,7 +1726,14 @@
$sql = $self->_mk_insert_row_sql($table, $cols);
foreach $row (@$rows) {
$nrows += $self->{numrows};
- if (!$dbh->do($sql, undef, @$row)) {
+ $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";
+ print "\n";
+ }
+ if (!$retval) {
$self->{numrows} = $nrows;
$ok = 0;
last;
@@ -1730,6 +1752,12 @@
my $sql = $self->_mk_delete_sql($table, $params, $cols, $row, $options);
$self->{sql} = $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";
+ print "\n";
+ }
&App::sub_exit($retval) if ($App::trace_subs);
return($retval);
}
@@ -1746,6 +1774,12 @@
my $sql = $self->_mk_update_sql($table, $params, $cols, $row, $options);
$self->{sql} = $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";
+ print "\n";
+ }
&App::sub_exit($retval) if ($App::trace_subs);
return($retval);
}
@@ -1760,6 +1794,12 @@
my $dbh = $self->{dbh};
my $retval = 0;
$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";
+ print "\n";
+ }
&App::sub_exit($retval) if ($App::trace_subs);
$retval;
}
@@ -1774,6 +1814,12 @@
my $dbh = $self->{dbh};
my $retval = 0;
$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";
+ print "\n";
+ }
&App::sub_exit($retval) if ($App::trace_subs);
$retval;
}