From 1788afbf5e73d8399ef080b88b5696195e89b1db Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 2 Oct 2018 22:35:37 +0100 Subject: [PATCH] Fix multi-param searches. Search facility now works correctly!!! --- modules/ORB/System/Recipe.pm | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/modules/ORB/System/Recipe.pm b/modules/ORB/System/Recipe.pm index 230c391..1903d6c 100644 --- a/modules/ORB/System/Recipe.pm +++ b/modules/ORB/System/Recipe.pm @@ -1022,8 +1022,15 @@ sub _join_fragment { } -## @method pricate $ _where_fragment($frag, $value, $wild, $params) +## @method private $ _where_fragment($frag, $value, $wild, $params) # Prepare values for inclusion in the WHERE section of the query +# +# @param frag The where fragment to generate. +# @param value The value to search for. +# @param wild If true, the value is surrounded by '%', and any '*' +# in the value will be converted to '%' +# @param params A reference to an array of params to pass to execute() +# @return The where fragment to use. sub _where_fragment { my $self = shift; my $frag = shift; @@ -1045,7 +1052,28 @@ sub _where_fragment { } +## @method private $ _where_fragment($frag, $values, $params) +# Prepare multiple values for inclusion in the WHERE section of the query. +# This should be used for "$field IN (...)" fragments where multiple values +# should be searched on. +# +# @param frag The where fragment to generate. +# @param values A reference to an array of values to search for. +# @param params A reference to an array of params to pass to execute() +# @return The where fragment to use. sub _multi_where_fragment { - my $self = shift; + my $self = shift; + my $frag = shift; + my $values = shift; + my $params = shift; + + my @place = (); + foreach my $value (@{$values}) { + push(@{$params}, $value); + push(@place, "?"); + } + + return $frag." (".join(",", @place).") "; } + 1;