]> granicus.if.org Git - pgbadger/commitdiff
Add support to named PREPARE and EXECUTE queries. Calls to EXECUTE statements are...
authorDarold Gilles <gilles@darold.net>
Mon, 28 Apr 2014 18:29:39 +0000 (20:29 +0200)
committerDarold Gilles <gilles@darold.net>
Mon, 28 Apr 2014 18:29:39 +0000 (20:29 +0200)
pgbadger

index 4ff8043d1c60d23690d83f4766ef128b785d9b76..d5274e2f52665a6cb10ed1a5a342bff26114eab9 100644 (file)
--- a/pgbadger
+++ b/pgbadger
@@ -8528,7 +8528,7 @@ sub parse_query
                return;
        }
 
-       # Look at bind parameters if any
+       # Look at bind/execute parameters if any
        if ($cur_info{$t_pid}{query}) {
 
                # Remove obsolete connection storage
@@ -8542,6 +8542,19 @@ sub parse_query
                                $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\t]+([^\s\t]+)[\s\t]+AS[\s\t]+(.*)//is)) {
+                               my $q_name = $1;
+                               my $real_query = $2;
+                               if ($cur_info{$t_pid}{query} =~ /\b$q_name\b/) {
+                                       $cur_info{$t_pid}{query} =~ s/EXECUTE[\s\t]+$q_name([\s\t]+)\(//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}{'bind'} = 1;
+                               }
+                               # go look at other params
+                               return;
                        }
                }
        }
@@ -8750,12 +8763,19 @@ sub store_queries
        $cur_info{$t_pid}{query} =~ s/[\t\s\r\n;]+$//s;
 
        # Replace bind parameters values in the query if any
-       if (exists $cur_info{$t_pid}{parameters}) {
+       if (exists $cur_info{$t_pid}{parameters} && ($cur_info{$t_pid}{parameters} =~ /[,\s]*\$(\d+)\s=\s/)) {
                my @t_res = split(/[,\s]*\$(\d+)\s=\s/, $cur_info{$t_pid}{parameters});
                shift(@t_res);
                for (my $i = 0 ; $i < $#t_res ; $i += 2) {
                        $cur_info{$t_pid}{query} =~ s/\$$t_res[$i]\b/$t_res[$i+1]/s;
                }
+       } else {
+               # parameters from EXECUTE statements
+               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;
+               }
        }
 
        # We only process stored object with query here