first shot at DBI tracing code
This commit is contained in:
parent
0c08e9c235
commit
5b25692561
3 changed files with 62 additions and 5 deletions
|
|
@ -203,7 +203,6 @@ sub buildHashRef {
|
|||
unless ($options->{noOrder}) {
|
||||
tie %hash, "Tie::IxHash";
|
||||
}
|
||||
$self->session->log->query($sql, $params);
|
||||
my $dbh = $self->dbh;
|
||||
my $results = $dbh->selectall_arrayref($sql, {}, @$params);
|
||||
if ($dbh->err) {
|
||||
|
|
@ -428,10 +427,15 @@ sub connect {
|
|||
my $pass = shift;
|
||||
my $params = shift;
|
||||
|
||||
require WebGUI::SQL::Trace;
|
||||
open my $trace_handle, '>:via(WebGUI::SQL::Trace)', $session;
|
||||
my (undef, $driver) = DBI->parse_dsn($dsn);
|
||||
my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError => 0, AutoCommit => 1,
|
||||
my $dbh = DBI->connect($dsn, $user, $pass, {
|
||||
RaiseError => 0,
|
||||
AutoCommit => 1,
|
||||
$driver eq 'mysql' ? (mysql_enable_utf8 => 1) : (),
|
||||
});
|
||||
$dbh->trace('2|SQL', $trace_handle);
|
||||
|
||||
unless (defined $dbh) {
|
||||
$session->errorHandler->error("Couldn't connect to database: $dsn : $DBI::errstr");
|
||||
|
|
|
|||
|
|
@ -132,9 +132,7 @@ sub execute {
|
|||
my $self = shift;
|
||||
my $placeholders = shift || [];
|
||||
my $sql = $self->{_sql};
|
||||
my $errorHandler = $self->db->session->errorHandler;
|
||||
$errorHandler->query($sql,$placeholders);
|
||||
$self->sth->execute(@{ $placeholders }) or $errorHandler->fatal("Couldn't execute prepared statement: $sql : With place holders: ".join(", ", @{$placeholders}).". Root cause: ". $self->errorMessage);
|
||||
$self->sth->execute(@{ $placeholders }) or $self->session->errorHandler->fatal("Couldn't execute prepared statement: $sql : With place holders: ".join(", ", @{$placeholders}).". Root cause: ". $self->errorMessage);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
55
lib/WebGUI/SQL/Trace.pm
Normal file
55
lib/WebGUI/SQL/Trace.pm
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package WebGUI::SQL::Trace;
|
||||
use strict;
|
||||
#use warnings;
|
||||
use 5.008008;
|
||||
|
||||
our $VERSION = '0.0.1';
|
||||
|
||||
sub PUSHED {
|
||||
my ($class, $mode, $fh) = @_;
|
||||
my $logger;
|
||||
return bless \$logger, $class;
|
||||
}
|
||||
|
||||
sub OPEN {
|
||||
my ($self, $session, $mode, $fh) = @_;
|
||||
$$self = $session;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub WRITE {
|
||||
my ($self, $buf, $fh) = @_;
|
||||
if ($buf =~ /\ABinding parameters: /) {
|
||||
my $sql = $buf;
|
||||
$sql =~ s/\ABinding parameters: //;
|
||||
my $sub;
|
||||
my $line;
|
||||
for ( my $i = 0; caller($i); $i++) {
|
||||
(my $package, undef, $line) = caller($i);
|
||||
next
|
||||
if $package eq 'WebGUI::SQL';
|
||||
next
|
||||
if $package eq 'WebGUI::SQL::ResultSet';
|
||||
($sub) = (caller($i + 1))[3];
|
||||
last;
|
||||
}
|
||||
$$self->log->debug("Query - $sub($line) : $sql");
|
||||
}
|
||||
return length($buf);
|
||||
}
|
||||
|
||||
sub CLOSE {
|
||||
my $self = shift;
|
||||
return 0;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
PerlIO::via::WebGUI - Log DBI output to WebGUI
|
||||
|
||||
=cut
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue