summaryrefslogtreecommitdiffstats
path: root/globals.pl
diff options
context:
space:
mode:
authordmose%mozilla.org <>2000-12-12 12:47:40 +0100
committerdmose%mozilla.org <>2000-12-12 12:47:40 +0100
commitcc0123cd61d04ea2935bf61da58e4db353b776a1 (patch)
treea82e9c0be31782ce40d71b7821a46d7d47d19854 /globals.pl
parent7033a5f254f8545ef65ed77a51080dd62601a5a4 (diff)
downloadbugzilla-cc0123cd61d04ea2935bf61da58e4db353b776a1.tar.gz
bugzilla-cc0123cd61d04ea2935bf61da58e4db353b776a1.tar.xz
add a stack to save the current global SQL state so that queries can be nested. used this mechanism to fix the 62618 regression. r=encido@mozilla.org
Diffstat (limited to 'globals.pl')
-rw-r--r--globals.pl42
1 files changed, 41 insertions, 1 deletions
diff --git a/globals.pl b/globals.pl
index bd1cf3ede..8cce0c78f 100644
--- a/globals.pl
+++ b/globals.pl
@@ -110,6 +110,30 @@ sub SyncAnyPendingShadowChanges {
}
+# This is used to manipulate global state used by SendSQL(),
+# MoreSQLData() and FetchSQLData(). It provides a way to do another
+# SQL query without losing any as-yet-unfetched data from an existing
+# query. Just push the current global state, do your new query and fetch
+# any data you need from it, then pop the current global state.
+#
+@::SQLStateStack = ();
+
+sub PushGlobalSQLState() {
+ push @::SQLStateStack, $::currentquery;
+ push @::SQLStateStack, [ @::fetchahead ];
+}
+
+sub PopGlobalSQLState() {
+ die ("PopGlobalSQLState: stack underflow") if ( $#::SQLStateStack < 1 );
+ @::fetchahead = @{pop @::SQLStateStack};
+ $::currentquery = pop @::SQLStateStack;
+}
+
+sub SavedSQLStates() {
+ return ($#::SqlStateStack + 1) / 2;
+}
+
+
my $dosqllog = (-e "data/sqllog") && (-w "data/sqllog");
sub SqlLog {
@@ -117,13 +141,21 @@ sub SqlLog {
my ($str) = (@_);
open(SQLLOGFID, ">>data/sqllog") || die "Can't write to data/sqllog";
if (flock(SQLLOGFID,2)) { # 2 is magic 'exclusive lock' const.
+
+ # if we're a subquery (ie there's pushed global state around)
+ # indent to indicate the level of subquery-hood
+ #
+ for (my $i = SavedSQLStates() ; $i > 0 ; $i--) {
+ print SQLLOGFID "\t";
+ }
+
print SQLLOGFID time2str("%D %H:%M:%S $$", time()) . ": $str\n";
}
flock(SQLLOGFID,8); # '8' is magic 'unlock' const.
close SQLLOGFID;
}
}
-
+
sub SendSQL {
my ($str, $dontshadow) = (@_);
my $iswrite = ($str =~ /^(INSERT|REPLACE|UPDATE|DELETE)/i);
@@ -637,6 +669,11 @@ sub DBNameToIdAndCheck {
sub quoteUrls {
my ($knownattachments, $text) = (@_);
return $text unless $text;
+
+ # make sure that any unfetched data from a currently running query
+ # is saved off rather than overwritten
+ #
+ PushGlobalSQLState();
my $base = Param('urlbase');
@@ -715,6 +752,9 @@ sub quoteUrls {
# And undo the quoting of "#" characters.
$text =~ s/%#/#/g;
+ # put back any query info in progress
+ PopGlobalSQLState();
+
return $text;
}