Francois Gouget : testbot: Add support for more collection filter types.

Alexandre Julliard julliard at winehq.org
Tue Jan 23 14:41:46 CST 2018


Module: tools
Branch: master
Commit: 114d3483d2bf714d7f4696466d5164666a99efb4
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=114d3483d2bf714d7f4696466d5164666a99efb4

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Tue Jan 23 05:32:30 2018 +0100

testbot: Add support for more collection filter types.

By default filters still return the rows where the specified field is
equal to one of the specified values. But now they can also be set to
return rows where the field is smaller, greater, different or like one
of the specified values.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 testbot/lib/ObjectModel/Collection.pm |  6 +++---
 testbot/lib/ObjectModel/DBIBackEnd.pm | 23 +++++++++++++++++++++--
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/testbot/lib/ObjectModel/Collection.pm b/testbot/lib/ObjectModel/Collection.pm
index a9ec995..86dee05 100644
--- a/testbot/lib/ObjectModel/Collection.pm
+++ b/testbot/lib/ObjectModel/Collection.pm
@@ -656,11 +656,11 @@ sub DeleteAll($)
   return undef;
 }
 
-sub AddFilter($$$)
+sub AddFilter($$$;$)
 {
-  my ($self, $PropertyName, $Value) = @_;
+  my ($self, $PropertyName, $Values, $Type) = @_;
 
-  $self->{Filters}{$PropertyName} = $Value;
+  $self->{Filters}{$PropertyName} = [($Type || "="), $Values];
 }
 
 sub GetFilters($)
diff --git a/testbot/lib/ObjectModel/DBIBackEnd.pm b/testbot/lib/ObjectModel/DBIBackEnd.pm
index 0594951..565d4a8 100644
--- a/testbot/lib/ObjectModel/DBIBackEnd.pm
+++ b/testbot/lib/ObjectModel/DBIBackEnd.pm
@@ -179,6 +179,16 @@ sub BuildFieldList($$)
   return $Fields;
 }
 
+my %_AllowedFilterTypes = (
+  "="    => 1,
+  "<>"   => 1,
+  "<"    => 1,
+  "<="   => 1,
+  ">"    => 1,
+  ">="   => 1,
+  "LIKE" => 1,
+);
+
 sub LoadCollection($$)
 {
   my ($self, $Collection) = @_;
@@ -202,7 +212,16 @@ sub LoadCollection($$)
       $Where .= " AND ";
     }
     my $PropertyDescriptor = $Collection->GetPropertyDescriptorByName($FilterProperty);
-    my $FilterValues = $Filters->{$FilterProperty};
+    my ($FilterType, $FilterValues) = @{$Filters->{$FilterProperty}};
+    if (!$_AllowedFilterTypes{$FilterType})
+    {
+      die "unknown '$FilterType' filter type";
+    }
+    if (!@$FilterValues)
+    {
+      die "no values for the '$FilterType' filter";
+    }
+
     if (@$FilterValues != 1)
     {
       $Where .= "(";
@@ -220,7 +239,7 @@ sub LoadCollection($$)
       }
       foreach my $ColName (@{$PropertyDescriptor->GetColNames()})
       {
-        $Where .= "$ColName = ?";
+        $Where .= "$ColName $FilterType ?";
         $Data[@Data] = $self->ToDb($ColValue, $PropertyDescriptor);
       }
     }




More information about the wine-cvs mailing list