chiark / gitweb /
Pass $dbh down through the stack, for better lifetime
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 16 Aug 2009 15:03:45 +0000 (16:03 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 16 Aug 2009 15:03:45 +0000 (16:03 +0100)
yarrg/web/lookup
yarrg/web/qtextstring
yarrg/web/qtextstringcheck
yarrg/web/query_age
yarrg/web/query_commod
yarrg/web/query_route
yarrg/web/routetrade

index 1b85ecc8b9d06b9dc5ba96b14b63e4cac99501c0..f194fc5d56d2cb3f4a6a2e955dd0b84c3493cfc2 100755 (executable)
@@ -160,7 +160,8 @@ foreach my $var (@vars) {
 
 die if $styles{Query} =~ m/[^a-z]/;
 
-dbw_connect($styles{Ocean});
+my $mydbh;
+my $dbh= ($mydbh= dbw_connect($styles{Ocean}));
 
 my $results_head_done=0;
 my $someresults= sub {
@@ -176,7 +177,8 @@ $debug => 0
 
 <hr>
 
-<& "query_$styles{Query}", %baseqf, %queryqf, %styles, quri => $quri,
+<& "query_$styles{Query}", %baseqf, %queryqf, %styles,
+    quri => $quri, dbh => $dbh,
     someresults => $someresults,
     emsgokorprint => sub {
        my ($emsg) = @_;
@@ -215,3 +217,8 @@ use HTML::Entities;
 use URI::Escape;
 
 </%init>
+<%cleanup>
+
+$mydbh->rollback() if $mydbh;
+
+</%cleanup>
index 3b0bd6b72e65b5f942ff1eff70b0786d9901c903..16aa372bd6794caad89992d6d7b2f2a976d519c2 100644 (file)
 
 </%doc>
 <%args>
+$qa => $m->caller_args(1)->{'qa'}
+$dbh
 $thingstring
 $emsgstore
 $perresult
-$qa => $m->caller_args(1)->{'qa'}
 </%args>
 <%perl>
 my $stringval= $qa->{$thingstring};
index 5ef8971f644b63991af5d6eb5379be7fec1da596..b2c101390589b01daf00d858c60f9d205d05ce83 100755 (executable)
@@ -43,6 +43,7 @@ $format
 $ctype => undef
 $string
 $what
+$dbh => undef
 </%args>
 
 <%flags>
@@ -58,7 +59,8 @@ use CommodsWeb;
 die if $what =~ m/[^a-z]/;
 my $chk= $m->fetch_comp("check_${what}");
 
-my $dbh= dbw_connect($ocean);
+my $mydbh;
+$dbh ||= ($mydbh= dbw_connect($ocean));
 
 my $sqlstmt= $chk->scall_method("sqlstmt");
 my $sth= $dbh->prepare($sqlstmt);
@@ -119,7 +121,7 @@ if ($format =~ /dump/) {
        print Dumper($emsg, $canontext, \@results);
 }
 
-$dbh->rollback();
+$mydbh->rollback() if $mydbh;
 
 return  $emsg,
        $canontext,
index 922e29f0c90031b97e1c485bb6fcb456946f8018..77d750c8c95ec2c0386b79f785111df215851e0b 100644 (file)
 
 
 </%doc>
+
+<%args>
+$quri
+$dbh
+</%args>
+
 <%once>
 my $meta_prettyprint_age= sub {
     my ($age,$floor,$plus) = @_;
@@ -56,7 +62,6 @@ eval '
 </%once>
 
 <%perl>
-
 my $now= time;
 
 my $row;
@@ -96,10 +101,8 @@ Time since this page loaded:
 <span id="daid_loaded">(not known; times above not updating)</span>
 
 <form action="lookup" method="get">
-% foreach my $a (keys %ARGS) {
-<input type="hidden" name="<% $a |h %>" value="<% $ARGS{$a} |h %>">
-% }
 <input type=submit name=submit value="Reload">
+<& "lookup:formhidden", ours => sub { 0; } &>
 </form>
 
 <&| script &>
@@ -128,8 +131,4 @@ Time since this page loaded:
 <%init>
 use POSIX;
 use CommodsWeb;
-my $dbh= dbw_connect('Midnight');
 </%init>
-<%cleanup>
-$dbh->rollback();
-</%cleanup>
index eddc0975d05f067358c6835a81710d97f8039b8d..9cb14ca6870e70abf887b518f2e9698313d67158 100644 (file)
@@ -35,6 +35,7 @@
 </%doc>
 <%args>
 $quri
+$dbh
 $commodstring => '';
 $someresults
 $emsgokorprint
@@ -56,7 +57,8 @@ Enter commodity (abbreviations are OK):<br>
 
 <form action="<% $quri->() |h %>" method="get">
 
-<&| qtextstring, qa => $qa, thingstring => 'commodstring', emsgstore => \$emsg,
+<&| qtextstring, qa => $qa, dbh => $dbh,
+    thingstring => 'commodstring', emsgstore => \$emsg,
     perresult => sub { ($commodname,$commodid)= @_; }
  &>
  size=80
index 66dee1dd08135de011871b15d71d963f7db235af..e9e358a433bc928b325a773651441b9ee25971d4 100644 (file)
@@ -35,6 +35,7 @@
 </%doc>
 <%args>
 $quri
+$dbh
 $routestring => '';
 $someresults
 $emsgokorprint
@@ -59,7 +60,8 @@ Enter route (islands, or archipelagoes, separated by |s or commas;
 
 <form action="<% $quri->() |h %>" method="get">
 
-<&| qtextstring, qa => $qa, thingstring => 'routestring', emsgstore => \$emsg,
+<&| qtextstring, qa => $qa, dbh => $dbh,
+    thingstring => 'routestring', emsgstore => \$emsg,
     perresult => sub {
        my ($canonname, $island, $arch) = @_;
        push @islandids, $island;
@@ -90,8 +92,6 @@ my $optionlistmap= sub {
        return $out;
 };
 
-my $dbh= dbw_connect($qa->{Ocean});
-
 $sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
                            ORDER BY archipelago;");
 $sth->execute();
@@ -120,8 +120,6 @@ foreach my $arch (keys %islandlistdata) {
                $optionlistmap->($islandlistdata{$arch}, '');
 }
 
-$dbh->rollback();
-
 </%perl>
 
 <&| script &>
@@ -206,5 +204,8 @@ for my $dd (0..$qa->{Dropdowns}-1) {
 
 % if (@islandids) {
 %      $someresults->();
-<& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &>
+<& routetrade,
+   dbh => $dbh,
+   islandids => \@islandids,
+   archipelagoes => \@archipelagoes &>
 % }
index 4475d27197915154c8cc4204556c10259dd355b2..1c5a3e49db2b184ac019b4a8177cb8838df59040 100644 (file)
@@ -1,4 +1,5 @@
 <%args>
+$dbh
 @islandids
 @archipelagoes
 </%args>
@@ -22,5 +23,4 @@ Route is as follows:
 
 <%init>
 use CommodsWeb;
-my $dbh= dbw_connect('Midnight');
 </%init>