From: Ian Jackson Date: Sun, 16 Aug 2009 15:03:45 +0000 (+0100) Subject: Pass $dbh down through the stack, for better lifetime X-Git-Tag: 3.4~173 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=commitdiff_plain;h=98610392fde2add293bee6199f2de1d6f88559d8;hp=b83c36dbcfb960638454348fef867f1456329867 Pass $dbh down through the stack, for better lifetime --- diff --git a/yarrg/web/lookup b/yarrg/web/lookup index 1b85ecc..f194fc5 100755 --- a/yarrg/web/lookup +++ b/yarrg/web/lookup @@ -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
-<& "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; +<%cleanup> + +$mydbh->rollback() if $mydbh; + + diff --git a/yarrg/web/qtextstring b/yarrg/web/qtextstring index 3b0bd6b..16aa372 100644 --- a/yarrg/web/qtextstring +++ b/yarrg/web/qtextstring @@ -36,10 +36,11 @@ <%args> +$qa => $m->caller_args(1)->{'qa'} +$dbh $thingstring $emsgstore $perresult -$qa => $m->caller_args(1)->{'qa'} <%perl> my $stringval= $qa->{$thingstring}; diff --git a/yarrg/web/qtextstringcheck b/yarrg/web/qtextstringcheck index 5ef8971..b2c1013 100755 --- a/yarrg/web/qtextstringcheck +++ b/yarrg/web/qtextstringcheck @@ -43,6 +43,7 @@ $format $ctype => undef $string $what +$dbh => undef <%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, diff --git a/yarrg/web/query_age b/yarrg/web/query_age index 922e29f..77d750c 100644 --- a/yarrg/web/query_age +++ b/yarrg/web/query_age @@ -33,6 +33,12 @@ + +<%args> +$quri +$dbh + + <%once> my $meta_prettyprint_age= sub { my ($age,$floor,$plus) = @_; @@ -56,7 +62,6 @@ eval ' <%perl> - my $now= time; my $row; @@ -96,10 +101,8 @@ Time since this page loaded: (not known; times above not updating)
-% foreach my $a (keys %ARGS) { - -% } +<& "lookup:formhidden", ours => sub { 0; } &>
<&| script &> @@ -128,8 +131,4 @@ Time since this page loaded: <%init> use POSIX; use CommodsWeb; -my $dbh= dbw_connect('Midnight'); -<%cleanup> -$dbh->rollback(); - diff --git a/yarrg/web/query_commod b/yarrg/web/query_commod index eddc097..9cb14ca 100644 --- a/yarrg/web/query_commod +++ b/yarrg/web/query_commod @@ -35,6 +35,7 @@ <%args> $quri +$dbh $commodstring => ''; $someresults $emsgokorprint @@ -56,7 +57,8 @@ Enter commodity (abbreviations are OK):
-<&| qtextstring, qa => $qa, thingstring => 'commodstring', emsgstore => \$emsg, +<&| qtextstring, qa => $qa, dbh => $dbh, + thingstring => 'commodstring', emsgstore => \$emsg, perresult => sub { ($commodname,$commodid)= @_; } &> size=80 diff --git a/yarrg/web/query_route b/yarrg/web/query_route index 66dee1d..e9e358a 100644 --- a/yarrg/web/query_route +++ b/yarrg/web/query_route @@ -35,6 +35,7 @@ <%args> $quri +$dbh $routestring => ''; $someresults $emsgokorprint @@ -59,7 +60,8 @@ Enter route (islands, or archipelagoes, separated by |s or commas; -<&| 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(); - <&| 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 &> % } diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 4475d27..1c5a3e4 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -1,4 +1,5 @@ <%args> +$dbh @islandids @archipelagoes @@ -22,5 +23,4 @@ Route is as follows: <%init> use CommodsWeb; -my $dbh= dbw_connect('Midnight');