From 7700199c34578ac34bfbce71cb8cb26ee76b3979 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 15 Nov 2007 18:35:58 +0000 Subject: [PATCH] Special-case empty arrays and single-element arrays in database wrappers. * single-element arrays were inefficient ("field IN (42)"), now using straight matches ("field=42") * empty arrays caused an error ("IN ()" is invalid syntax), now will evaluate to 0 (false) --- includes/Database.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/includes/Database.php b/includes/Database.php index 4455228aed..f611f8e73c 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -1564,7 +1564,15 @@ class Database { } elseif ( ($mode == LIST_SET) && is_numeric( $field ) ) { $list .= "$value"; } elseif ( ($mode == LIST_AND || $mode == LIST_OR) && is_array($value) ) { - $list .= $field." IN (".$this->makeList($value).") "; + if( count( $value ) == 0 ) { + // Empty input... or should this throw an error? + $list .= '0'; + } elseif( count( $value ) == 1 ) { + // Special-case single values, as IN isn't terribly efficient + $list .= $field." = ".$this->addQuotes( $value[0] ); + } else { + $list .= $field." IN (".$this->makeList($value).") "; + } } elseif( is_null($value) ) { if ( $mode == LIST_AND || $mode == LIST_OR ) { $list .= "$field IS "; -- 2.20.1