X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDebug%2FPrettyPrint.pm;h=4cae709042d5348fa208f36003b3547b6bd607d9;hb=84c65032102185049278b5ebc5651458b92152dd;hp=ba6fbfc7b3f41dc46551bd53838046f2d78a1401;hpb=728f26a266b8bcfa7fad80617d4015c7d0b81474;p=dbsrgits%2FSQL-Abstract.git diff --git a/lib/DBIx/Class/Storage/Debug/PrettyPrint.pm b/lib/DBIx/Class/Storage/Debug/PrettyPrint.pm index ba6fbfc..4cae709 100644 --- a/lib/DBIx/Class/Storage/Debug/PrettyPrint.pm +++ b/lib/DBIx/Class/Storage/Debug/PrettyPrint.pm @@ -1,5 +1,8 @@ package DBIx::Class::Storage::Debug::PrettyPrint; +use strict; +use warnings; + use base 'DBIx::Class::Storage::Statistics'; use SQL::Abstract::Tree; @@ -20,12 +23,33 @@ sub new { sub print { my $self = shift; my $string = shift; + my $bindargs = shift; + + my $use_placeholders = !!$self->_sqlat->fill_in_placeholders; + + # DBIC pre-quotes bindargs + $bindargs = [map { s/^'//; s/'$//; } @{$bindargs}] if $use_placeholders; + + my $formatted = $self->_sqlat->format($string, $bindargs) . "\n"; - my $formatted = $self->_sqlat->format($string); + $formatted = "$formatted: " . join ', ', @{$bindargs} + unless $use_placeholders; $self->next::method($formatted, @_); } +sub query_start { + my ($self, $string, @bind) = @_; + + if(defined $self->callback) { + $string =~ m/^(\w+)/; + $self->callback->($1, "$string: ".join(', ', @bind)."\n"); + return; + } + + $self->print($string, \@bind); +} + 1; =pod