[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OSSTEST PATCH 10/60] history reporting (nfc): Bind by name in cacheable_query


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
  • Date: Fri, 14 Aug 2020 18:21:15 +0100
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
  • Delivery-date: Fri, 14 Aug 2020 17:26:34 +0000
  • Ironport-sdr: +rFNKiVJx0Vt65WitQUTUDeTRO/vq1k9/eu2nbxSeSjfE44/mzExFUmXeZ4AECk6N4rQkySLaC HsO3etkG5Lw9jnoQ+EtGutB6OB2/ZDOAdVVGFmhOGXooGMuWy1MNyTdKNxqv2wkcY4NNwsa/xF Xv3RKkUEKYj+6uC3Cpk3jOqHpxF1FlU/NH04pirUliFFXn9Hpkrk6L85LoR/Rfg17tDXiUwVKY OcG+vTBPCd36NhUsV/vzMvrujBP4Fx3mmK0q7wf6UXSxNjLwRdOd/Rm4e7i6V8fd27Mw9hS8Az 6ZE=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

cacheable_query used to simply pass $jr->{flight} and ->{job}.  But we
want this to be reuseable for other kinds of query, with different
cache keys.

So bind by name: we expect the caller to use :name placeholders in the
query.  We can then look through the prepared query parameters, and
fish the corresponding values out of $jr.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 sg-report-host-history | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sg-report-host-history b/sg-report-host-history
index 90369ce4..8c5cd105 100755
--- a/sg-report-host-history
+++ b/sg-report-host-history
@@ -197,7 +197,11 @@ sub cacheable_fn ($$$) {
 sub cacheable_query ($$$) {
     my ($q, $jr, $cachekey) = @_;
     cacheable_fn($jr, $cachekey, sub {
-       $q->execute($jr->{flight}, $jr->{job});
+       foreach my $k (keys %{ $q->{ParamTypes} }) {
+           $k =~ m/^:/ or die "$k ?";
+           $q->bind_param($k, $jr->{$'} // die "$k ?");
+       }
+       $q->execute();
        return $q->fetchrow_hashref();
     });
 }
@@ -259,7 +263,7 @@ sub reporthost ($) {
     our $endedq //= db_prepare(<<END);
        SELECT finished, testid, status AS laststepstatus
          FROM steps
-        WHERE flight=? AND job=? AND finished IS NOT NULL
+        WHERE flight=:flight AND job=:job AND finished IS NOT NULL
         ORDER BY finished DESC
         LIMIT 1
 END
@@ -267,13 +271,13 @@ END
     our $infoq //= db_prepare(<<END);
        SELECT blessing, branch, intended
          FROM flights
-        WHERE flight=? AND ?!='X'
+        WHERE flight=:flight AND :job != 'X'
 END
 
     our $allocdq //= db_prepare(<<END);
        SELECT testid, finished, status
          FROM steps
-        WHERE flight=? AND job=?
+        WHERE flight=:flight AND job=:job
           AND (testid='hosts-allocate' OR step='ts-hosts-allocate')
         ORDER BY finished ASC
         LIMIT 1
-- 
2.11.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.