]> granicus.if.org Git - pgbadger/commitdiff
Reapply fix missing replacement of bind parameters after some extra code cleaning...
authorGilles Darold <gilles@darold.net>
Fri, 5 Oct 2018 13:16:09 +0000 (15:16 +0200)
committerGilles Darold <gilles@darold.net>
Fri, 5 Oct 2018 13:16:09 +0000 (15:16 +0200)
pgbadger

index b167d147e2dd8c91c2d89b6e5f6a657bc531b539..925074f99bd8ebd97fcfe234b6d14c0d7dba35ef 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -13192,23 +13192,28 @@ sub parse_query
                delete $conn_received{$cur_info{$t_pid}{pid}};
 
                # The query is complete but we are missing some debug/info/bind parameter logs
-               if ($is_log_level) {
+               if ($cur_info{$t_pid}{loglevel} eq 'LOG' && $prefix_vars{'t_loglevel'} eq 'DETAIL') {
 
                        # Apply bind parameters if any
-                       if (($prefix_vars{'t_loglevel'} eq 'DETAIL') && ($prefix_vars{'t_query'} =~ /parameters: (.*)/)) {
+                       if ($prefix_vars{'t_query'} =~ /parameters: (.*)/) {
                                $cur_info{$t_pid}{parameters} = "$1";
                                # go look at other params
                                return;
                        # replace the execute statements with the prepared query and set the parameters
-                       } elsif (($prefix_vars{'t_loglevel'} eq 'DETAIL') && ($prefix_vars{'t_query'} =~ s/prepare: PREPARE\s+([^\s]+)\s+AS\s+(.*)//is)) {
+                       } elsif ($prefix_vars{'t_query'} =~ s/prepare: PREPARE\s+([^\s]+)(\s*\([^\)]*\))?\s+AS\s*(.*)/[ EXECUTE $1 (PARAM) ]/is) {
                                my $q_name = $1;
-                               my $real_query = $2;
+                               my $real_query = $3;
                                if ($cur_info{$t_pid}{query} =~ /\b$q_name\b/) {
-                                       $cur_info{$t_pid}{query} =~ s/EXECUTE\s+$q_name(\s+)\(//is;
-                                       $cur_info{$t_pid}{parameters} = $cur_info{$t_pid}{query};
-                                       $cur_info{$t_pid}{parameters} =~ s/\)$//;
-                                       $cur_info{$t_pid}{query} = $real_query;
+                                       $cur_info{$t_pid}{query} =~ s/EXECUTE\s+$q_name\s*\((.*)\)[;]*$//is;
+                                       $cur_info{$t_pid}{parameters} = $1;
+                                       $prefix_vars{'t_query'} =~ s/\(PARAM\)/($cur_info{$t_pid}{parameters})/;
+                                       $cur_info{$t_pid}{query} = $prefix_vars{'t_query'} . ' - ' . $real_query;
                                        $cur_info{$t_pid}{'bind'} = 1;
+                                       my @t_res = split(/[\s]*,[\s]*/, $cur_info{$t_pid}{parameters});
+                                       for (my $i = 0 ; $i <= $#t_res ; $i++) {
+                                               my $num = $i + 1;
+                                               $cur_info{$t_pid}{query} =~ s/\$$num\b/$t_res[$i]/s;
+                                       }
                                }
                                # go look at other params
                                return;