From: Arthur Axel "fREW" Schmidt Date: Thu, 9 Sep 2010 03:16:54 +0000 (+0000) Subject: integrate placeholder population with DBIC X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84c65032102185049278b5ebc5651458b92152dd;p=scpubgit%2FQ-Branch.git integrate placeholder population with DBIC --- 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 diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 36a2ce9..b1ec93d 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -103,6 +103,7 @@ my %indents = ( my %profiles = ( console => { + fill_in_placeholders => 1, indent_string => ' ', indent_amount => 2, newline => "\n", @@ -110,6 +111,7 @@ my %profiles = ( indentmap => { %indents }, }, console_monochrome => { + fill_in_placeholders => 1, indent_string => ' ', indent_amount => 2, newline => "\n", @@ -117,6 +119,7 @@ my %profiles = ( indentmap => { %indents }, }, html => { + fill_in_placeholders => 1, indent_string => ' ', indent_amount => 2, newline => "
\n",