Item14755: Add zeroresults parameter for DBQUERY

pencil
Priority: Enhancement
Current State: Closed
Released In: n/a
Target Release:
Applies To: Extension
Component: DBCachePlugin
Branches: master
Reported By: StefanH
Waiting For:
Last Change By: MichaelDaum
I was missing the possibility to provide a replacement text to show in case no results are returned for a DBQUERY like in SEARCH.

So I created this small patch for lib/Foswiki/Plugins/DBCachePlugin/Core.pm:
--- lib/Foswiki/Plugins/DBCachePlugin/Core-12.0.pm   2018-10-01 13:13:38.000000000 +0200
+++ lib/Foswiki/Plugins/DBCachePlugin/Core.pm   2018-10-12 15:58:08.288052000 +0200
@@ -206,6 +206,7 @@
   my $theLimit = $params->{limit} || '';
   my $theSkip = $params->{skip} || 0;
   my $theHideNull = Foswiki::Func::isTrue($params->{hidenull}, 0);
+  my $theZeroResults = $params->{zeroresults};
   my $theRemote = Foswiki::Func::isTrue($params->remove('remote'), 0);
   my $theNewline = $params->{newline};
   my $doWarnings = Foswiki::Func::isTrue($params->{warn}, 1);
@@ -287,7 +288,10 @@
   if ($error) {
     return $doWarnings ? _inlineError($error) : "";
   }
-  return "" if $theHideNull && (!$hits || $hits->count <= $theSkip);
+  if (!$hits || $hits->count <= $theSkip) {
+      return $theZeroResults if $theZeroResults;
+      return '' if $theHideNull;
+  }
 
   # format
   my @result = ();

This adds the new parameter 'zeroresults'. If it is set and no results are found, its value is returned instead. The 'hidenull' parameter still works the same way as before.

I don't know if it works correctly with the 'skip' parameter though and admit I don't really understand what it should do. In my tests I always got the same results regardless of a skip-value.

-- StefanH - 30 Aug 2018

Updated and verified for DBCachePlugin 12.00.

-- StefanH - 12 Oct 2018

Will call it nullformat to be in line with ClassificationPlugin, TopicInteractionPlugin and LdapNgPlugin

-- MichaelDaum - 26 Nov 2018
 
Topic revision: r3 - 26 Nov 2018, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy