Procházet zdrojové kódy

Converting InList operator to a boolean condition if the array is empty.

Kenric Nugteren před 11 měsíci
rodič
revize
9d630ef23e
1 změnil soubory, kde provedl 18 přidání a 11 odebrání
  1. 18 11
      inabox.database.sqlite/SQLiteProvider.cs

+ 18 - 11
inabox.database.sqlite/SQLiteProvider.cs

@@ -1513,23 +1513,30 @@ public class SQLiteProvider : IProvider
 
             if (filter.Operator == Operator.InList || filter.Operator == Operator.NotInList)
             {
-                // if, and only if the list contains Guids, we can safely bypass the 
-                // 1000-parameter limit by using building the string ourselves
-                if (filter.Value is Guid[] list)
+                if(filter.Value is Array arr && arr.Length == 0)
                 {
-                    result = string.Format("(" + operators[filter.Operator] + ")", prop, string.Format("\"{0}\"", string.Join("\",\"", list)));
+                    result = filter.Operator == Operator.InList ? "1 = 0" : "1 = 1";
                 }
-                else if (filter.Value is IEnumerable enumerable)
+                else
                 {
-                    var paramlist = new List<object>();
-                    foreach (var item in enumerable)
+                    // if, and only if the list contains Guids, we can safely bypass the 
+                    // 1000-parameter limit by using building the string ourselves
+                    if (filter.Value is Guid[] list)
                     {
-                        var sParam = string.Format("@p{0}", command.Parameters.Count);
-                        command.Parameters.AddWithValue(sParam, Encode(item, mexp.Type));
-                        paramlist.Add(sParam);
+                        result = string.Format("(" + operators[filter.Operator] + ")", prop, string.Format("\"{0}\"", string.Join("\",\"", list)));
                     }
+                    else if (filter.Value is IEnumerable enumerable)
+                    {
+                        var paramlist = new List<object>();
+                        foreach (var item in enumerable)
+                        {
+                            var sParam = string.Format("@p{0}", command.Parameters.Count);
+                            command.Parameters.AddWithValue(sParam, Encode(item, mexp.Type));
+                            paramlist.Add(sParam);
+                        }
 
-                    result = string.Format("(" + operators[filter.Operator] + ")", prop, string.Join(",", paramlist));
+                        result = string.Format("(" + operators[filter.Operator] + ")", prop, string.Join(",", paramlist));
+                    }
                 }
             }
             else if (filter.Operator == Operator.InQuery || filter.Operator == Operator.NotInQuery)